3

I have an edge of a polygon (convex or concave). I want to find out if, going straight from start to end point of that edge, I have to turn right or left to get inside or outside of polygon. How can I check that?

gvlasov
  • 18,638
  • 21
  • 74
  • 110

2 Answers2

3

Traverse the whole polygon in that direction. If you find that you went clockwise, then the interior is to the right; if you went counter-clockwise, it's to the left.

Beta
  • 96,650
  • 16
  • 149
  • 150
  • 2
    should have linked to this: http://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order/1165943#1165943 – agentp Mar 04 '14 at 12:56
2

Another approach:

Project a perpendicular line and count how many times it crosses other edges.

odd -> interior

zero or even -> exterior

Equivalently If you happen to have a well optimized point-in-polygon routine available you can project a point some epsilon off the line and throw it into the inside test.

Community
  • 1
  • 1
agentp
  • 6,849
  • 2
  • 19
  • 37