Skip to main content
1 of 2

What is the best way to check if a point is inside an irregular polygon?

I'm using Javascript (https://github.com/substack/point-in-polygon) to test if a point is inside polygon, however I think it's adapted from https://www.ecse.rpi.edu/~wrf/Research/Short_Notes/pnpoly.html

Following are the list of points,

let points = [
            [ 42.34624, -71.06024 ],
            [ 42.33558, -71.06616 ],
            [ 42.32632, -71.05835 ],
            [ 42.32987, -71.05428 ],
            [ 42.34732, -71.05432 ],
            [ 42.34618, -71.05973 ],
            [ 42.34624, -71.06024 ]
        ];
let testPoint = [
            [42.33288, -71.05804]
            
        ];`

let isInside = pp(testPoint, points);
expect(isInside).to.equal(true); // always fails

enter image description here

I'm not sure why it fails though. Is it because the algorithm doesn't cope with this "type" of polygon? Any hints please? Please point me to any alternatives to this approach as well.