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. They also measure, orient and round 2D outlines, and frame a sweep along a polyline: the frames or matrices that carry a profile along it without twisting. 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 Bit.Inputs.Base.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 Bit.Inputs.Base.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,
      });

    polygon

    • Finds the unit normal of the plane a polyline encloses, read as a closed outline.

      Newell's method makes it hold for an outline that is not convex or not quite flat. It points the way the outline turns by the right-hand rule; an outline with no area gives undefined. Example: [[0,0,0], [4,0,0], [4,4,0], [0,4,0]] -> [0, 0, 1]

      Parameters

      Returns Vector3

      The unit normal, or undefined

      const normal = bitbybit.polyline.polygonNormal({ polyline: { points: [[0, 0, 0], [4, 0, 0], [4, 4, 0], [0, 4, 0]] } });
      
    • Measures the area a polyline encloses, read as a closed outline in its own plane.

      The polyline need not repeat its first point at its end. An outline that is not quite flat gives the area of its outline seen along its normal. Example: [[0,0,0], [4,0,0], [4,4,0], [0,4,0]] -> 16

      Parameters

      Returns number

      The area in square model units

      const area = bitbybit.polyline.polygonArea({ polyline: { points: [[0, 0, 0], [4, 0, 0], [4, 4, 0], [0, 4, 0]] } });
      

    polygon 2d

    • Measures the area of a flat outline, signed by the way it runs.

      The area is positive when the outline runs counter-clockwise and negative when it runs clockwise, so the sign tells which way an outline turns. Example: [[0,0], [4,0], [4,4], [0,4]] -> 16; the same corners reversed -> -16

      Parameters

      Returns number

      The signed area in square model units

      const area = bitbybit.polyline.signedArea2d({ points: [[0, 0], [4, 0], [4, 4], [0, 4]] });
      
    • Measures the length around a flat outline, its closing side included.

      Example: [[0,0], [3,0], [3,4]] -> 12

      Parameters

      Returns number

      The perimeter in model units

      const around = bitbybit.polyline.perimeter2d({ points: [[0, 0], [3, 0], [3, 4]] });
      
    • Tells whether a point lies inside a flat outline.

      It counts the outline's sides a ray from the point crosses, so it holds for outlines that are not convex; a point exactly on a side may fall either way. Example: [2,2] in [[0,0], [4,0], [4,4], [0,4]] -> true

      Parameters

      Returns boolean

      True when the point is inside

      const inside = bitbybit.polyline.isPointInside2d({ points: [[0, 0], [4, 0], [4, 4], [0, 4]], point: [2, 2] });
      
    • Makes a flat outline run counter-clockwise, or clockwise.

      An outline already running that way comes back as it was; otherwise its corners are reversed. Example: [[0,0], [0,4], [4,4], [4,0]], counter-clockwise -> [[4,0], [4,4], [0,4], [0,0]]

      Parameters

      Returns Bit.Inputs.Base.Point2[]

      The corners, running the asked way

      const ccw = bitbybit.polyline.orient2d({ points: [[0, 0], [0, 4], [4, 4], [4, 0]], counterClockwise: true });
      
    • Rounds the corners of a flat outline with arcs, drawn as short straight pieces.

      Every corner takes radius, or its own entry of radiusList; a radius of 0 leaves it sharp. A radius too large for the sides beside its corner is refused. Example: a 10 by 10 square, radius 2 -> four quarter arcs at the corners

      Parameters

      • inputs: RoundPolygon2Dto

        The outline, the radius or radii and the pieces per quarter turn

      Returns Bit.Inputs.Base.Point2[]

      The rounded outline's points

      const rounded = bitbybit.polyline.roundCorners2d({ points: [[0, 0], [10, 0], [10, 10], [0, 10]], radius: 2, segments: 8 });
      

    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,
      });

    sweep

    • Finds the direction a path heads in at each of its points.

      At an inner point it bisects the segments either side; at the ends it follows the end segments, unless startTangent or endTangent is given. Every direction has length 1. A closed polyline is refused. Example: [[0,0,0], [1,0,0], [1,1,0]] -> [[1,0,0], [0.707,0.707,0], [0,1,0]]

      Parameters

      Returns Vector3[]

      One unit direction per point

      const directions = bitbybit.polyline.tangents({ polyline: { points: [[0, 0, 0], [1, 0, 0], [1, 1, 0]] } });
      
    • Places a frame at each point of a path, facing along it without twisting.

      Each normal is the path's direction there. Each direction, the profile's X axis, turns by the smallest angle between points, so a swept profile does not spin. firstDirection sets it at the start. Example: a straight path along X -> frames that differ only in origin

      Parameters

      Returns Bit.Inputs.Base.Frame[]

      One frame per point

      const frames = bitbybit.polyline.sweepFrames({ polyline: { points: [[0, 0, 0], [0, 0, 5], [5, 0, 10]] }, firstDirection: [1, 0, 0] });
      
    • Builds a matrix per point of a path that places a flat profile there, for sweeping it.

      Each puts the XY plane on that point's sweepFrames frame, Z along the path, and stretches it across a bend so the pieces either side meet. Example: a straight path along Z -> matrices that only move up it

      Parameters

      Returns TransformMatrix[]

      One placement matrix per point

      const placements = bitbybit.polyline.sweepPlacements({ polyline: { points: [[0, 0, 0], [0, 0, 5], [5, 0, 10]] } });
      const ring = bitbybit.point.transformPoints({ points: [[1, 0, 0], [0, 1, 0], [-1, 0, 0]], transformation: [placements[1]] });
    • Rounds the corners of a path in space with arcs, drawn as short straight pieces.

      Where the segments beside a corner are too short for radius, it gets the largest arc that fits half of each. The ends stay; a closed polyline is refused. Example: [[0,0,0], [10,0,0], [10,10,0]], radius 2 -> one quarter arc at the corner

      Parameters

      Returns Bit.Inputs.Polyline.PolylinePropertiesDto

      The rounded path

      const rounded = bitbybit.polyline.roundCorners({ polyline: { points: [[0, 0, 0], [10, 0, 0], [10, 10, 0]] }, radius: 2, segments: 8 });
      

    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] }),
      });