how to check whether the point is inside or not

126 Views Asked by At

When the line segments that form closed shape is given how to check whether the given point lies inside the diagram or not

for example enter image description here AB ,BC ,CD,DE,EA are the line segments given and i know the co-ordinates of endpoints each line segment . Now how to find whether a given point is inside the diagram or not ?

My approach: By using ray casting or winding number for checking whether the point is inside or not . But i am struck at "how to find the vertices of polygon"

1

There are 1 best solutions below

6
On

You need to find the equations of your segments, and try parallel lines.

If a point is inside a triangle every line parallel to a side of triangle and passing through that point will intersect the other two sides at points between vertices.

On the other hand for a point outside the triangle one of the lines parallel to the three sides do not intersect the triangle at all.

Same is true for the pentagon.