# how to check whether the point is inside or not

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 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"

• This link and this one seem relevant. But it appears to me that your problem isn't with using ray casting or winding numbers, but how to convert a set of line segments to a polygon. Is this correct?
– Jens
May 6 '18 at 1:03

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.

• The above only seems to work for convex polygons.
– Jens
May 6 '18 at 0:45
• That is what I meant, you need to check each triangle and the pentagon which are convex. May 6 '18 at 1:46
• The above methld won't work for every case ... Sometimes the diagram may be concave also May 6 '18 at 5:50
• I agree we have to divide the region into conves subregions and work with each section separately. May 6 '18 at 8:39
• i think this method is more complicated to implement and have more time complexity. I am searching for efficient algorithm May 6 '18 at 19:32