Point in Polygon with actionscript 3
Testing whether a point is inside a polygon is a basic operation in computer graphics. Here a example of how to do that in a very simple way.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | private function insidePolygon(pointList:Array, p:Point):Boolean { var counter:int = 0; var i:int; var xinters:Number; var p1:PointTest; var p2:PointTest; var n:int = pointList.length; p1 = pointList[0]; for (i = 1; i <= n; i++) { p2 = pointList[i % n]; if (p.y > Math.min(p1.y, p2.y)) { if (p.y <= Math.max(p1.y, p2.y)) { if (p.x <= Math.max(p1.x, p2.x)) { if (p1.y != p2.y) { xinters = (p.y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y) + p1.x; if (p1.x == p2.x || p.x <= xinters) counter++; } } } } p1 = p2; } if (counter % 2 == 0) { return(false); } else { return(true); } } |
Categories: Actionscript 3, Actionscript 3, Flash


Ahh! Excelente! Gracias por compartirlo. Estoy pensando en hacer una app que involucre recorte de figuras, algo me dice que esto me servirá para orientarme