Saturday, 15 September 2012

c++ - how to detemine if a line segment is inside of a polygon? -


We have a line segment L defined by two points from polygon And a polygon p define with 4 or more digits, I need an algorithm that is L inside p ?

Edit: The line segment should be completely inside the polygon, if only partially it will be defined as outside

For example, the picture below: < / P>

Click to view image

Some other examples:

Click to view image

step 1 : Does it cross any side of L? If yes, LP is not in it. If not, see Step 2

Step 2 : Where is the middle of L? If the MP is inside, LP is inside.

In the case of bus:

Editing, more clarification : Two cases: at least one edge of LP Crosses. Then L at least partially drink.

  • LP does not cross any edge. Then El is either outside or inside and as the whole l is outside or inside, it is enough to test the position of any point of L (except the two ends of L). And if a point is outside or out of a polygon, then there is a classic problem (which has a dedicated Wikipedia page).

  • No comments:

    Post a Comment