Skip to content

Instantly share code, notes, and snippets.

@isedgar
isedgar / ray-casting.js
Created June 4, 2021 00:38
Check if a 2D point is inside 2D simple polygon. It works with convex and concave polygons.
function ray_casting(point, polygon){
var n=polygon.length,
is_in=false,
x=point[0],
y=point[1],
x1,x2,y1,y2;
for(var i=0; i < n-1; ++i){
x1=polygon[i][0];
x2=polygon[i+1][0];