How can I determine whether a 2D Point is within a Polygon?

前端 未结 30 2097
醉梦人生
醉梦人生 2020-11-21 05:06

I\'m trying to create a fast 2D point inside polygon algorithm, for use in hit-testing (e.g. Polygon.contains(p:Point)). Suggestions for effective tech

30条回答
  •  囚心锁ツ
    2020-11-21 05:59

    The trivial solution would be to divide the polygon to triangles and hit test the triangles as explained here

    If your polygon is CONVEX there might be a better approach though. Look at the polygon as a collection of infinite lines. Each line dividing space into two. for every point it's easy to say if its on the one side or the other side of the line. If a point is on the same side of all lines then it is inside the polygon.

提交回复
热议问题