Bitbybit Docs
    Preparing search index...

    Class Polyline

    Polylines: chains of straight segments through a list of points, held as plain objects of the form { points, isClosed }. A closed polyline joins its last point back to its first. The methods here measure a polyline, convert it to segments or lines, find where polylines cross, sort loose segments into chains and size fillets for its corners. Lengths are in model units.

    Index

    Constructors

    convert

    • Splits the polyline into line objects, one per segment, each with a start and an end point.

      A closed polyline also gets the segment from its last point back to its first, unless the two coincide. Example: three points -> two lines, or three when closed

      Parameters

      Returns Line3[]

      One line per segment, in order

      const lines = bitbybit.polyline.polylineToLines({ polyline: { points: [[0, 0, 0], [1, 0, 0], [1, 1, 0]], isClosed: true } });
      
    • Splits the polyline into segments, each a pair of points.

      A closed polyline also gets the segment from its last point back to its first, unless the two coincide. Fewer than two points give no segments. Example: four points, closed -> four segments around the loop

      Parameters

      Returns Segment3[]

      One point pair per segment, in order

      const segments = bitbybit.polyline.polylineToSegments({ polyline: { points: [[0, 0, 0], [1, 0, 0], [1, 1, 0]], isClosed: false } });
      

    create

    fillet

    • Finds the largest fillet for every corner of the polyline, each limited to the nearer half of its segments so the fillets never overlap.

      A closed polyline includes the two corners at its ends. Fewer than three points give an empty list.

      Parameters

      Returns number[]

      One radius per corner, in the order of the corners

      const radii = bitbybit.polyline.maxFilletsHalfLine({
      polyline: { points: [[0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]], isClosed: true },
      tolerance: 1e-7,
      });
    • Finds one fillet radius that fits every corner of the polyline: the smallest of the per-corner maximums under the half-segment rule.

      Fewer than three points, or any corner that allows no fillet, give 0.

      Parameters

      Returns number

      The radius that fits every corner, in model units

      const radius = bitbybit.polyline.safestFilletRadius({
      polyline: { points: [[0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]], isClosed: true },
      tolerance: 1e-7,
      });

    get

    • Measures the polyline by adding up the straight distances between neighboring points.

      The closing segment of a closed polyline is not counted. Example: [[0,0,0], [3,0,0], [3,4,0]] -> 7

      Parameters

      Returns number

      The length in model units

      const len = bitbybit.polyline.length({ polyline: { points: [[0, 0, 0], [3, 0, 0], [3, 4, 0]] } });
      

    intersection

    • Finds the points where two polylines cross each other, testing every segment of one against every segment of the other.

      Crossings closer together than the tolerance are reported once. Example: two polylines forming an X -> the point in the middle

      Parameters

      Returns Point3[]

      The crossing points; empty when there are none

      const crossings = bitbybit.polyline.twoPolylineIntersection({
      polyline1: { points: [[0, 0, 0], [2, 2, 0]] },
      polyline2: { points: [[0, 2, 0], [2, 0, 0]] },
      tolerance: 1e-6,
      });

    intersections

    • Finds the points where the polyline crosses itself.

      Neighboring segments are not tested against each other, and crossings closer together than the tolerance are reported once. Example: a figure-eight -> its one crossing point

      Parameters

      Returns Point3[]

      The crossing points; empty when there are none

      const crossings = bitbybit.polyline.polylineSelfIntersection({
      polyline: { points: [[0, 0, 0], [2, 2, 0], [2, 0, 0], [0, 2, 0]] },
      tolerance: 1e-6,
      });

    sort

    • Joins loose segments into polylines by matching up ends that meet within the tolerance.

      Segments that connect end to end become one polyline each chain; segments that touch nothing become single-segment polylines. Example: ten scattered segments forming two chains -> two polylines

      Parameters

      Returns Polyline3[]

      The polylines the segments form

      const chains = bitbybit.polyline.sortSegmentsIntoPolylines({
      segments: [[[0, 0, 0], [1, 0, 0]], [[1, 0, 0], [1, 1, 0]], [[5, 5, 0], [6, 5, 0]]],
      tolerance: 1e-5,
      });

    transforms

    • Applies a transformation matrix, or a list of them in order, to every point of the polyline.

      Example: a translation by [5,0,0] -> every point moved 5 along X

      Parameters

      Returns Bit.Inputs.Polyline.PolylinePropertiesDto

      A new polyline with the transformed points

      const moved = bitbybit.polyline.transformPolyline({
      polyline: { points: [[0, 0, 0], [1, 0, 0]] },
      transformation: bitbybit.transforms.translationXYZ({ translation: [5, 0, 0] }),
      });