Have ideas to improve npm?Join in the discussion! »

    segseg

    0.2.2 • Public • Published

    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.

    Install

    npm i [email protected]

    Version

    0.2.2

    License

    MIT

    Last publish

    Collaborators

    • avatar