Skip to content

Instantly share code, notes, and snippets.

@yanandrey
Created July 15, 2021 14:19
Show Gist options
  • Save yanandrey/3db1589612f7bef815ba67c723b76112 to your computer and use it in GitHub Desktop.
Save yanandrey/3db1589612f7bef815ba67c723b76112 to your computer and use it in GitHub Desktop.
public bool IsPointInPolygon(List<Location> poly, Location point)
{
int i, j;
var c = false;
for (i = 0, j = poly.Count - 1; i < poly.Count; j = i++)
{
if ((poly[i].Lt <= point.Lt && point.Lt < poly[j].Lt
|| poly[j].Lt <= point.Lt && point.Lt < poly[i].Lt)
&& point.Lg < (poly[j].Lg - poly[i].Lg) * (point.Lt - poly[i].Lt)
/ (poly[j].Lt - poly[i].Lt) + poly[i].Lg)
{
c = !c;
}
}
return c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment