Calculate if an object is inside a set of coordinates?

前端 未结 2 424
孤独总比滥情好
孤独总比滥情好 2021-02-04 01:03

I have a set of X and Y points that builds a shape and I need to know if an object is inside it or not what is the calculation to it ?

X and Y coords example:

         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-02-04 01:43

    I've always done it like so:

    Pick a point you know to be outside the shape.
    Make a line between that point and the point you're trying to find whether it's inside the shape or not.
    Count the number of sides of the shape the line crosses. 
    
    If the count is odd, the point is inside the shape.
    If the count is even, the point is outside the shape.
    

提交回复
热议问题