Skip to content

Instantly share code, notes, and snippets.

@SirGordon
Created January 13, 2016 15:33
Show Gist options
  • Save SirGordon/6ae07d317f5406d503d9 to your computer and use it in GitHub Desktop.
Save SirGordon/6ae07d317f5406d503d9 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment