lines-self-chop

0.0.13 • Public • Published

lines-self-chop

given an array of 3d line segments, this tool slices the lines at all points of intersection, returning non-intersecting sub-segments.

works with any number of lines.

this tool uses rbush-3d for efficiency.

example

Installation

npm i lines-self-chop

Usage

var chopLines = require('lines-self-chop');

// for example, if the input is 2 lines forming an X,
// the output is 4 shorter lines meeting at the center, 
// forming the same X.

//each line segment is two 3d points [[x,y,z],[x,y,z]]
var line1 = [[0,0,0],[5,0,5]];
var line2 = [[0,0,5],[5,0,0]];

var minDist = 0.01; //mininum distance between lines for them to be considered intersecting [default 0.1]

var result = chopLines([line1, line2], minDist); 

//result =
// [
//     [ [ 0, 0, 0 ], [ 2.5, 0, 2.5 ] ],
//     [ [ 2.5, 0, 2.5 ], [ 5, 0, 5 ] ],
//     [ [ 0, 0, 5 ], [ 2.5, 0, 2.5 ] ],
//     [ [ 2.5, 0, 2.5 ], [ 5, 0, 0 ] ]
// ]

stonks

Package Sidebar

Install

npm i lines-self-chop

Weekly Downloads

1

Version

0.0.13

License

CC0-1.0

Unpacked Size

6.47 kB

Total Files

4

Last publish

Collaborators

  • stonkpunk