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

前端 未结 30 2166
醉梦人生
醉梦人生 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 06:04

    To deal with the following special cases in Ray casting algorithm:

    1. The ray overlaps one of the polygon's side.
    2. The point is inside of the polygon and the ray passes through a vertex of the polygon.
    3. The point is outside of the polygon and the ray just touches one of the polygon's angle.

    Check Determining Whether A Point Is Inside A Complex Polygon. The article provides an easy way to resolve them so there will be no special treatment required for the above cases.

提交回复
热议问题