Closest Point on a Polygon
<p>It can be explained better with an image so let’s take a look at this figure. As you can see points 1 and 3 are inside the polygon but point 2 is not because point 1 has 1 crossing (odd), 2 has 2 crossings (even) and 3 has 3 crossings (odd).</p>
<p>I ran a semi-infinite ray horizontally (increasing x, fixed y) out from the test point, and count how many edges it crosses. At each crossing, the ray switches between inside and outside. For this case, the closest point to that point is the point itself.</p>
<p><a href="https://javedali-iitkgp.medium.com/get-closest-point-on-a-polygon-23b68e26a33"><strong>Click Here</strong></a></p>