Answer the question
In order to leave comments, you need to log in
How is it checked whether a point belongs to a polygon using the angle method?
Explain how the angle method is implemented and what it is?
Answer the question
In order to leave comments, you need to log in
Read this article: https://habrahabr.ru/post/144921/
It should become clearer.
I understand that this is a method of "calculate how many revolutions a polygon makes around a point".
To do this, we take each edge of the polygon (in some order of traversal, i.e. each point is the first for one edge, the second for the other), and we consider at what angle this segment is visible from the point. An important trick here is the corner with a sign. Those. +30 degrees if the segment goes from the first point to the second counterclockwise, and -30 if exactly the same segment is unfolded.
To do this, you need to take the vector and scalar products of vectors by points - these will be the sine and cosine of the angle, multiplied by the lengths of the vectors. They, without even dividing by lengths, can be passed to the atan2 () function, and it will give you the angle value. already with the correct sign. Although you can play it safe - the angle should be from -pi to +pi. If it is greater than pi, then you need to subtract 2pi from it, if it is less than -pi, then add.
All these angles are simply summed up. If the point lies outside, then the answer will be 0. If the point is inside, then the answer will be + -2pi. If the point lies on the border, then the devil knows, but this case is easy to detect. If any of the summed angles is equal to +-pi, then the point is on the segment. It would also be necessary to separately check the case that the point coincided with one of the vertices of the polygon. There will be a null vector and atan will not work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question