Skip to content
segment to segment intersection (2d)
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test
.gitignore
.travis.yml
README.md
index.js
package.json

README.md

segseg

Intersection detection between two line segments in 2d space

Signature

segseg(x1, y1, x2, y2, x3, y3, x4, y4)

returns:

  • [x, y] - intersection
  • true - colinear
  • undefined - no intersection

Usage

var segseg = require('segseg');
/*
                (0, 5)
                   |
  (-10, 0) ----------------  (10, 0)
                   |
                (0, -5)
*/
var isect = segseg(-10, 0, 10, 0, 0, 5, 0, -5);

console.log(isect.join(',')) // outputs: 0,0

Credits

This code was ported from Mukesh Prasad's example implementation which was included in graphics gems 2.

Something went wrong with that request. Please try again.