# ray casting on earth's surface

Is it safe to use ray casting algorithm to check if a coordinate is inside a polygon specified as coordinates? Purpose of my question is because the longitudes are not parallel in a Cartesian sense, so is that a problem? If so, how big of a problem is it (for how big polygons it can matter for example), and how can I correct it? For example, can I map lat/lon to another domain and use ray casting safely?

I don't know much about GIS, but willing to learn anything related to my question.

-
Consider that spherical polygons are in one-to-one correspondence with their cones at the origin, which is are polyhedra in three dimensions. (Although such a polyhedron is infinite in extent, it could be capped by, say, intersecting it with a giant cube centered at the origin, making it a finite (compact) polyhedron.) Because raycasting works for polyhedra, then--if correctly applied--it must work for spherical polygons too. – whuber Apr 23 '13 at 20:08
Thanks. Your answer is a little bit beyond my understanding (infinite/finite-compact polyhedron?) but it is good to know it should work. What do you mean by if correctly applied ? The very common implementation of the algorithm should be adapted or it is enough ? – mete Apr 24 '13 at 14:00
I don't know what you mean by "very common implementation." Do you have a reference? Note that many textbook implementations do not correctly handle degenerate situations (e.g., points on the boundary or rays parallel to an edge); this gets more complicated in 3D. BTW, the first two lines of the article at encyclopediaofmath.org/index.php/Polyhedron,_abstract explain (badly) what a compact polyhedron is. In plainer language, it is a polyhedron entirely contained within some sphere: it doesn't have any parts extending infinitely far from the origin. – whuber Apr 24 '13 at 14:33
Yes, sorry for ambiguity. This is what I mean by common implementation: ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html . Also I dont need an exact implementation, I mean edge cases can be handled anyway, just I dont want it to reach very wrong results for polyhedrons (I believe I meant polygon on sphere). – mete Apr 24 '13 at 19:16
That page doesn't actually give an algorithm for polyhedra: it merely speculates that one can be developed. It's correct, but of course the devil is in the details. In your case, there are some subtle pitfalls. For instance, if your polygons were originally created in a projected coordinate system (they might have been traced on a map, for instance), then their edges are actually likely to be curvilinear and you are best off doing the point-in-polygon calculation in the original (2D) coordinate system. – whuber Apr 24 '13 at 20:04