![]() Let us use the cumbersome notation PAX to denote the angle between segment AP and AX, where X is always a point on the horizontal line passing by A with x coordinate bigger than the maximum between the x coordinate of A and the x coordinate of B. point A is always below point B) and a point P. Let us take into account a segment AB (the point A having y coordinate always smaller than B's y coordinate, i.e. The following text explain one of the possible ways. So the main part of the algorithm is how we determine if a ray intersects a segment. So, if we crossed an odd number of borders we were surely inside, otherwise we were outside we can follow the ray backward to see it better: starting from outside, only an odd number of crossing can give an inside: outside-inside, outside-inside-outside-inside, and so on (the - represents the crossing of a border). The last "country" we land on is surely outside (since the inside of the polygon is finite, while the ray continues towards infinity). Where the function ray_intersects_segment return true if the horizontal ray starting from the point P intersects the side (segment), false otherwise.Īn intuitive explanation of why it works is that every time we crossĪ border, we change "country" (inside-outside, or outside-inside), but ![]() Given a point and a polygon, check if the point is inside or outside the polygon using the ray-casting algorithm. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. The list of authors can be seen in the page history. The original article was at Point_in_polygon. You are encouraged to solve this task according to the task description, using any language you may know.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |