How to check if point is in polygon in Javascript
I came across this piece of C code (i think) that's supposed to be a neat way to check if a point is within a (concave or convex) polygon and want to use it in my JS program: int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy) { int i, j, c = 0; for (i = 0, j = nvert-1; i < nvert; j = i++) { if ( ((verty[i]>testy) != (verty[j]>testy)) && (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) ) c = !c; } return c; } nvert: Number of vertices in the polygon. Whether to repeat the first vertex at the end. vertx, verty: Arrays containing the x-