How to check if point is in polygon in Javascript

有些话、适合烂在心里 提交于 2019-12-03 20:23:39

vertx and verty should be arrays and should have the values there. Initialize them with

vertx = []; verty = [];

Then the function is pretty much the same (assuming it is correct)

function pnpoly(var nvert, var vertx, var verty, var testx, var testy).
{
  var 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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!