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:

Bitbybit Platform

Lines between two spirals in Rete

rete logoRete
Script Source (rete)
{
"id": "rete-v2-json",
"nodes": {
"spiral": {
"id": "spiral",
"name": "bitbybit.point.spiral",
"customName": "spiral",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"phi": 0.9,
"numberPoints": 60,
"widening": 3,
"radius": 6,
"factor": 1
},
"inputs": {},
"position": [
40,
40
]
},
"lifted": {
"id": "lifted",
"name": "bitbybit.point.translatePoints",
"customName": "translate points",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"points": {
"connections": [
{
"node": "spiral",
"output": "result",
"data": {}
}
]
},
"translation": {
"connections": [
{
"node": "up",
"output": "result",
"data": {}
}
]
}
},
"position": [
460,
40
]
},
"up": {
"id": "up",
"name": "bitbybit.vector.vectorXYZ",
"customName": "vector xyz",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"x": 0,
"y": 5,
"z": 0
},
"inputs": {},
"position": [
40,
460
]
},
"turned": {
"id": "turned",
"name": "bitbybit.point.rotatePointsCenterAxis",
"customName": "rotate points center axis",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"angle": 120,
"axis": [
0,
1,
0
],
"center": [
0,
0,
0
]
},
"inputs": {
"points": {
"connections": [
{
"node": "lifted",
"output": "result",
"data": {}
}
]
}
},
"position": [
880,
40
]
},
"lines": {
"id": "lines",
"name": "bitbybit.line.linesBetweenStartAndEndPoints",
"customName": "lines between start and end points",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"startPoints": {
"connections": [
{
"node": "spiral",
"output": "result",
"data": {}
}
]
},
"endPoints": {
"connections": [
{
"node": "turned",
"output": "result",
"data": {}
}
]
}
},
"position": [
1300,
40
]
}
},
"modules": {}
}

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.

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.
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.