0

I'm trying to find out whether a point in lat, lon lie inside a polygon formed by four random points on earth.

Can someone help me out with a algorithm with sudo code in java.

Thanks in advance.

ardhani
  • 303
  • 1
  • 11

1 Answers1

0

As long as the polygon does not intersect the poles or the datum limit (the meridian at the border of longitude -180 / 180),
you can use a simple point in polygon algorithm, written for cartesian space. In this special case there is no need to convert to cartesian coordinates.
Just use x = longitude and y = latitude.

The point in polygon algorithm should be based on on the "ray intersection" method. (A ray parallel to x-axis through the point of question, that is outside always intersects the polygon an even number of times, while an point inside always an odd number of times.

Such a code is only a few lines long.

AlexWien
  • 28,470
  • 6
  • 53
  • 83