Advertisement
Rochet2

Point in Polygon - theory

Dec 8th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. Checking if a point is inside an area inside X,Y coordination.
  2.  
  3. Input assumed to be a list of points that define a simple polygon.
  4. Input is checked to be a convex. If it is not a convex then it is checked that it is a simple polygon.
  5. If the input is not a convex then the input is assumed to consist of points p1,p2,...,pn where pi is connected to pi+1 and p1 is connected to pn - this is because if the points do not form a convex then it is impossible to define what area the points are supposed to define unless there is additional infomation or assumptions.
  6.  
  7. A point P is given and it should be checked whether the point is inside or outside of the defined area.
  8.  
  9. You may need/want to sort the points so that they are in the list, for example, clockwise to ease algorithms for checking.
  10.  
  11. For a convex it should be easy to check if point is inside it. This case can be handled directly.
  12. However if the area defined is a simple polygon that is not a convex then the polygon can be convexed (split into multiple convexes).
  13. For example the polygon can be triangulated with an algorithm (google it) and then for each triangle you can check whether the point is inside at least one of the triangles or not. If it is inside one, then it is inside the defined area.
  14. The convexing should be done only once per polygon and not for each time a new point P is checked.
  15.  
  16. To check if a point is inside a triangle you can compare the angle of the point P relative to 2 different triangle points.
  17. Then from the angle you can see whether the point is on the "outer" or "inner" side of the line the two triangle points define.
  18. This can be done for each 3 sides of the triangle and if all result in the point being inside, then the point is inside the triangle. Same type of checking applies to convexes in general.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement