Bitbybit Docs
    Preparing search index...

    Class Line

    Straight lines between two points, held as plain objects of the form { start, end }, and the segment form [start, end] of the same thing. The methods here build lines, measure and transform them, convert between the two forms, place points along them and find where two lines cross. Lengths are in model units.

    Index

    Constructors

    convert

    • Turns a line object into its segment form, the pair [start, end].

      Example: { start: [0,0,0], end: [10,5,0] } -> [[0,0,0], [10,5,0]]

      Parameters

      Returns Segment3

      The segment

    • Turns each line object into its segment form, the pair [start, end].

      Example: three lines -> three segments, in the same order

      Parameters

      Returns Segment3[]

      One segment per line

    • Turns a segment, the pair [start, end], into a line object.

      Example: [[0,0,0], [10,5,0]] -> { start: [0,0,0], end: [10,5,0] }

      Parameters

      Returns Line3

      The line

    • Turns each segment, a pair [start, end], into a line object.

      Example: three segments -> three lines, in the same order

      Parameters

      Returns Line3[]

      One line per segment

    create

    • Builds a line object from a start and an end point.

      Example: start [0,0,0], end [10,5,0] -> { start: [0,0,0], end: [10,5,0] }

      Parameters

      Returns Line3

      The line object

      const line = bitbybit.line.create({ start: [0, 0, 0], end: [10, 5, 0] });
      
    • Builds a segment, the pair-of-points form of a line, from a start and an end point.

      Example: start [0,0,0], end [10,5,0] -> [[0,0,0], [10,5,0]]

      Parameters

      Returns Segment3

      The segment as [start, end]

      const segment = bitbybit.line.createSegment({ start: [0, 0, 0], end: [10, 5, 0] });
      
    • Joins each point to the next with a line, so a list of points becomes a chain of lines.

      Example: [[0,0,0], [5,0,0], [5,5,0]] -> two lines, [0,0,0] to [5,0,0] and [5,0,0] to [5,5,0]

      Parameters

      Returns Line3[]

      One line per pair of neighboring points

      const chain = bitbybit.line.linesBetweenPoints({ points: [[0, 0, 0], [5, 0, 0], [5, 5, 0]] });
      
    • Pairs each start point with the end point at the same position and joins them with a line.

      A pair whose two points coincide makes no line and is left out. Example: starts [[0,0,0], [5,0,0]] and ends [[0,5,0], [5,5,0]] -> two lines

      Parameters

      Returns Line3[]

      One line per pair, skipping pairs of length 0

      const rungs = bitbybit.line.linesBetweenStartAndEndPoints({
      startPoints: [[0, 0, 0], [5, 0, 0]],
      endPoints: [[0, 5, 0], [5, 5, 0]],
      });

    get

    • Measures the straight distance from the start of a line to its end.

      Example: { start: [0,0,0], end: [3,4,0] } -> 5

      Parameters

      Returns number

      The length in model units

    • Finds the point a fraction of the way along a line: 0 gives the start, 1 the end, 0.5 the middle.

      A fraction outside 0 to 1 continues past the ends. Example: { start: [0,0,0], end: [10,0,0] } at 0.5 -> [5,0,0]

      Parameters

      Returns Point3

      The point on the line

      const middle = bitbybit.line.getPointOnLine({ line: { start: [0, 0, 0], end: [10, 0, 0] }, param: 0.5 });
      

    intersection

    • Finds the point where two lines cross.

      With checkSegmentsOnly on, the crossing must lie within both segments; off, the lines extend without end. Parallel lines, lines that pass each other without meeting, and segments that do not reach each other give undefined. The tolerance says how close counts as meeting. Example: [0,0,0] to [10,0,0] and [5,-5,0] to [5,5,0] -> [5,0,0]

      Parameters

      Returns Point3

      The crossing point, or undefined when there is none

      const crossing = bitbybit.line.lineLineIntersection({
      line1: { start: [0, 0, 0], end: [10, 0, 0] },
      line2: { start: [5, -5, 0], end: [5, 5, 0] },
      checkSegmentsOnly: true,
      tolerance: 1e-6,
      });

    operations

    • Swaps the start and end of a line, so it runs the other way.

      Example: { start: [0,0,0], end: [10,5,0] } -> { start: [10,5,0], end: [0,0,0] }

      Parameters

      Returns Line3

      A new line running the other way

    transforms

    • Applies a transformation matrix, or a list of them in order, to both ends of a line.

      Example: { start: [0,0,0], end: [10,0,0] } moved by [5,5,0] -> { start: [5,5,0], end: [15,5,0] }

      Parameters

      Returns Line3

      A new line with the transformed ends

      const moved = bitbybit.line.transformLine({
      line: { start: [0, 0, 0], end: [10, 0, 0] },
      transformation: bitbybit.transforms.translationXYZ({ translation: [5, 5, 0] }),
      });
    • Applies a different transformation to each line: the first transformation to the first line, and so on.

      Example: three lines with three translations -> each line moved by its own translation

      Parameters

      Returns Line3[]

      The transformed lines, in the same order

      const placed = bitbybit.line.transformsForLines({
      lines: [{ start: [0, 0, 0], end: [1, 0, 0] }, { start: [0, 0, 0], end: [0, 1, 0] }],
      transformation: bitbybit.transforms.translationsXYZ({ translations: [[0, 1, 0], [0, 2, 0]] }),
      });