Skip to main content

Lines in Bitbybit

Line category icon

View Full Source & Details on GitHub

bitbybit.line works with straight lines between two points in 3D. Lengths are in model units.

Two forms of the same line​

  • A line is an object { start: [x, y, z], end: [x, y, z] }. Its direction runs from start to end.
  • A segment is the same thing as a pair of points: [[x1, y1, z1], [x2, y2, z2]].

lineToSegment and linesToSegments turn line objects into segments; segmentToLine and segmentsToLines go the other way.

Building lines​

  • create builds a line object from a start and an end point, and createSegment builds the segment form.
  • linesBetweenPoints joins each point of a list to the next, so n points give a chain of n - 1 lines. The chain is not closed back to the first point.
  • linesBetweenStartAndEndPoints pairs each start point with the end point at the same position in a second list. A pair whose two points coincide makes no line and is left out, so the result can be shorter than the lists.

Here the points of a spiral are lifted and turned, and linesBetweenStartAndEndPoints joins each point to its partner. The lines weave a twisted surface:

Lines between two spirals
Bitbybit Platform

Lines between two spirals in Rete

Rete

Reading and measuring​

  • getStartPoint and getEndPoint read the ends.
  • length measures the straight distance from start to end.
  • getPointOnLine gives the point a fraction param of the way along: 0 is the start, 1 the end and 0.5 (the default) the middle. A value outside 0 to 1 continues past the ends.
  • distanceToPoint measures how far a point lies from the line: square to it for a point beside it, and to the nearer end for a point past either end.

Reversing and transforming​

These give new lines and leave their input as it was.

  • reverse swaps the start and end, so the line runs the other way.
  • transformLine applies a transformation matrix, or a list of them in order, to both ends of a line. Matrices come from transform functions such as those in bitbybit.babylon.transforms.
  • transformsForLines applies a different transformation to each line: the first to the first line, and so on.

Where two lines cross​

lineLineIntersection gives the point where two lines cross, or undefined when they do not.

  • With checkSegmentsOnly on (the default), the crossing must lie within both lines between their ends. Off, both lines extend without end.
  • Parallel lines, lines that pass each other without meeting and lines shorter than the tolerance give undefined.
  • tolerance (default 0.01, in model units) sets how close the lines must come to count as meeting.

Every function​

FunctionWhat it does
createBuilds a line object from a start and an end point.
createSegmentBuilds a segment, the pair-of-points form of a line, from a start and an end point.
distanceToPointMeasures how far a point lies from a line, to the nearest point between its start and end.
getEndPointReads the end point of a line.
getPointOnLineFinds the point a fraction of the way along a line: 0 gives the start, 1 the end, 0.5 the middle.
getStartPointReads the start point of a line.
lengthMeasures the straight distance from the start of a line to its end.
lineLineIntersectionFinds the point where two lines cross.
linesBetweenPointsJoins each point to the next with a line, so a list of points becomes a chain of lines.
linesBetweenStartAndEndPointsPairs each start point with the end point at the same position and joins them with a line.
linesToSegmentsTurns each line object into its segment form, the pair [start, end].
lineToSegmentTurns a line object into its segment form, the pair [start, end].
reverseSwaps the start and end of a line, so it runs the other way.
segmentsToLinesTurns each segment, a pair [start, end], into a line object.
segmentToLineTurns a segment, the pair [start, end], into a line object.
transformLineApplies a transformation matrix, or a list of them in order, to both ends of a line.
transformsForLinesApplies a different transformation to each line: the first transformation to the first line, and so on.