Random Polyline Generator

Generate a two-dimensional polyline from bounded random steps with total length and bounding-box metadata.

Description

Generate a 2D polyline as bounded random coordinate steps from the origin, with length and bounding box.

A polyline connects ordered points with straight segments. Its length is the sum of segment lengths, while an axis-aligned bounding box records the coordinate extremes rather than the traveled distance. Cartesian coordinates provide the point representation used here.1

The output contains points as [x, y] arrays, length, and boundingBox. The first point is always [0, 0]. maximumStep bounds each coordinate increment, so it neither fixes the Euclidean segment length nor confines the whole path to a box of that size.

When to use Random Polyline Generator

Use it for random-walk drawing fixtures or polyline length and bounding-box exercises.

How to use Random Polyline Generator and understand its results

  1. Enter integer vertexCount from 2 through 128 and positive finite maximumStep no greater than 1e100.
  2. Run and connect points in returned order. vertexCount includes the starting origin, so there are vertexCount − 1 segments.
  3. Read length in the shared coordinate unit and boundingBox as the visited coordinate extent. Choose rendering, viewport, and line styling separately.
dx,dy = −M + 2M × randomDraw; next point = previous point + [dx,dy]

Every new vertex consumes two draws. Each component lies from −M toward M; a segment can approach √2M in length.

length = sum(hypot(dx,dy)); width = maxX − minX; height = maxY − minY

The implementation calls the polyline-length and bounding-box calculators on the completed points array, including the origin.

json
{
  "input": {
    "vertexCount": 3,
    "maximumStep": 5
  },
  "randomDraw": 0.25,
  "output": {
    "boundingBox": {
      "minX": -5,
      "minY": -5,
      "maxX": 0,
      "maxY": 0,
      "height": 5,
      "width": 5
    },
    "length": 7.0710678118654755,
    "points": [
      [
        0,
        0
      ],
      [
        -2.5,
        -2.5
      ],
      [
        -5,
        -5
      ]
    ]
  }
}

Draws 0.5 give zero increments, permitting repeated vertices and zero length. The cumulative path can extend beyond ±maximumStep, revisit points, cross itself, or happen to return to its origin. It is not automatically closed.

Limitations and assumptions

The default source is Math.random; no seed input or cryptographic entropy guarantee is provided. Repeated runs may select the same result, and the distribution depends on the random source.

The path has no fixed segment length, unique-vertex rule, intersection avoidance, closure requirement, or bounded global extent. Independent coordinate-step sampling is not a uniform angular direction sampler.

Floating-point accumulation affects long paths and extreme scales. The tool does not render a graph or provide an image file.

Alternative or Complementary methods

Use the deterministic measurement tools for a path you already have. Point-cloud generators provide independent positions rather than cumulative connected steps.

References

  1. Algebra and Trigonometry 2e: The Rectangular Coordinate Systems and Graphs — OpenStax, Rice University

Similar or alternative tools

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies