Skip to content

Instantly share code, notes, and snippets.

@painkkiller
Forked from SirGordon/is point in polygon.as
Created January 13, 2016 15:33
Show Gist options
  • Save painkkiller/d9bba078760aeea72084 to your computer and use it in GitHub Desktop.
Save painkkiller/d9bba078760aeea72084 to your computer and use it in GitHub Desktop.
public static function isPointInPolygon(point:Vector3D, polygon:Vector.<Vector3D>):Boolean {
var i:int, j:int, nvert:int = polygon.length;
var result:Boolean = false;
for (i = 0, j = nvert - 1; i < nvert; j = i++) {
if (((polygon[i].z) >= point.z != (polygon[j].z >= point.z)) &&
(point.x <= (polygon[j].x - polygon[i].x) * (point.z - polygon[i].z) / (polygon[j].z - polygon[i].z) + polygon[i].x))
result = !result;
}
return result;
}
@painkkiller
Copy link
Author

у меня Vector3D, в котором y игнорируется
ты можешь использовать Point
и вместо z везде используй y
у меня просто x и z используются
т.к. y вверх а полигон всегда лежит на земле, ровно как и точка (y==0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment