Link to home
Start Free TrialLog in
Avatar of Perplexity
Perplexity

asked on

Latitude, Longitude, polygons, and points.

Hello,

I am trying to figure out a way to determine whether a give point on a map (literally anywhere on earth) falls within the bounds of a polygon drawn from a list of ordinal lat/lon points.  The polygon could have any number of sides, as long as none intersect.

I am guessing that starting by converting the lat/lon values (which also have a N, S, E, or W associated with them) into a totally numerical representation is how I should start.  If that is correct, what is the best way to do it?

For the record, I already have my lat/lon values converted to a decimal number rather than minutes and seconds, etc.

Does anyone have a good algorithm to determine if the point is inside a polygon that is mapped on the surface of the earth?  I am looking for a very precise way to do this, as the precision is important in this case.
ASKER CERTIFIED SOLUTION
Avatar of JayeshKitukale
JayeshKitukale

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Christopher Kile
You have a special condition here that is not taken into account by the algorithms in the page to which JayeshKitukale's excellent link points:  since you are working on a closed surface (the flattened sphere of Earth), some sets of your points might form polygons which overlap themselves.  Are your polygons liable to do that?  
Avatar of Perplexity
Perplexity

ASKER

Thanks for the responses thus far...if I understand the question correctly, the answer is that there should be no self-overlapping polygons.  The points that comprise each polygon are kept in order and no lines can intersect another line in a given polygon.

With that assumption, are those the algorithms to make the determination whether or not a set of coordinates falls within the bounds of a polygon formed by a given ordered set of coordinates?

Thanks again for the guidance.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
"The points that comprise each polygon are kept in order and no lines can intersect another line in a given polygon"
But every adjacent pair of lines intersect ie have a common point. You probably mean that they do not cross.
If the lines on your map follow great circles, they may not follow straight lines along a cylindrical equidistant projection.
If this makes a difference, you may want to use a gnomonic projection to do your 2-d  point in polygoin test
The easy way is to take the problem into 3D.

Take the lat/lons of the vertices of the polygon and find their (x,y,z).

Move the polygon vertices away from the center of the earth until they all can see each other over the surface of the earth.  

Create a 3d polytope from the aforesaid vertices and the center of the earth.

To test if a point is in the polygon, just take it to 3d and see if it is in the polytope.
From what Perplexity has told us, "the point is inside a polygon that is mapped on the surface of the earth."  JayeshKitukale's page of algorithms tell us when a point lies within the polygon on a plane, and whether a point falls within a polyhedron.  

Perplexity,

How accurate do you need this to be?  I ask because I used to get problems from a teacher, who developed models for predictive purposes in her day job.  She gave us a problem once where there was no symbolic solution, but which could be approximate by either circular or sinusoidal approximations (she chose the former, simpler calculation).  In your case, do you need to have your algorithm tell you that a point lies on a polygon on an approximated Earth's surface? The planet is somewhat pear-shaped, but even by simply assuming Earth is a sphere, there can be quite a distance between the surface of a flat polygon described by a plane cutting through each vertex plotted on the Earth's surface as opposed to the actual position on the surface - this sort of thing is sometimes called the approximation error.  As the size of the polygons decreases, the approximation error decreases.  What are the acceptable levels of approximation error for the problem with which you are faced?


SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
(unless your polygon includes the north pole) due north is a good direction to pick, since a north-south great circle easily maps to latitude longitude coordinates,
however, care is still needed to do the
   Calculate the y value where ray intersects this segment
step properly

> there is no guarantee that more than one edge of a polygon will lie along a "great circle."
So one edge is guaranteed but the other edges are not?
How are the edges defined if not by great circles?  are they loxodromes? some other curve?