简体   繁体   中英

Find any point inside a polygon

Question:

How to find any point inside a polygon, whereby this point would be at least the distance epsilon away from the edge (to avoid numerical problems).

Explanation:

The problem I want to find a solution for is different from the usual is a point inside a polygon problem. I guess that this could be simpler, or built upon the answer to the point in polygon algorithm (ray casting for example).

The process could start by picking the pseudo-middlepoint of the polygon (min+max)/2 . This point could be tested by ray casting or something similar. If the point isn't inside another point is randomly choosen somewhere between the min and max of each axis.

The polygons we are talking about have an irregular shape, defined by dozens to a hundred vertices. There would be no self intersections. I'm concerned about numerical problems if I pick a point near the edges of the polygon, so a requirement that the point isn't very close to an edge has to be added. It doesn't need to be especially computationally efficient, just not crazy inefficient.

Could this be solved in a simple, elegant way?

I'm using Lua.

Pick a point on the polygon which is an extreme in some direction, eg the point with largest y co-ordinate. Move a short distance in the direction of the line bisecting the lines from that point to the points on either side of it. Check that you are in the polygon and if not reduce the distance moved.

If there are ties and the points to either side of it have the same y co-ordinate you will have to try test points on either side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM