gsm icon     interpolating    mapping    searching geospatial methods

Spheres: Miscellaneous Algorithms.


Inflection Point of a Great Circle: 

The inflection point (apex) of a great circle is the point at which it achieves it's highest latitude. The antipode of this point is the point at which the great circle achieves it's lowest latitude. The latitude of these two points defines the latitude range of the great circle and one extreme of the latitude range of any great circle arc that contains one of them.

In Cartesian space we have three equations and three unknowns:

x2+ y2+ z2= r2    - the sphere.
ax + by + cz = 0    - the plane of the great circle.
z = zmax    - the plane of the maximum latitude achieved by the great circle.

a, b, c and r are constants. x, y and z range over {-r, r}. The inflection point is where z is maximized so we need to find the (x, y) pair that maximizes z.

Solving for x and y we get:
x = (-cz - ((b2 * (-cz))/(a2 + b2)) (-+) (ab * sqrt(-(cz)2 +(r2 - z2)a2 +(r2 - z2)b2)/(a2+b2)))/a
and
y = (-bcz (+-) a * sqrt[-(cz)2 +(r2 - z2)a2 +(r2 - z2)b2]) / (a2 + b2)

Note the radical. If the term under the radical is negative there is no (real) solution. Consequently:

-(cz)2 +(r2 - z2)a2 +(r2 - z2)b2  >=  0

so
-c2z2 + r2a2 -z2a2 +r2b2 -z2b2  >=  0
r2a2 + r2b2  >=  z2(c2+a2+b2)
(r2a2 + r2b2) / (c2+a2+b2)  >=  z2

which means
-sqrt[(r2a2 + r2b2) / (c2+a2+b2)]  <=  z  <=  +sqrt[(r2a2 + r2b2) / (c2+a2+b2)]

so
zmax  =  +sqrt[(r2a2 + r2b2) / (c2+a2+b2)]

which means
-(czmax)2 +(r2 - zmax2)a2 +(r2 - zmax2)b2
=  -c2((r2a2 + r2b2) / (c2+a2+b2)) + r2a2 -a2((r2a2 + r2b2) / (c2+a2+b2)) + r2b2 -b2((r2a2 + r2b2) / (c2+a2+b2))
=  -(a2 + b2 + c2)*((r2a2 + r2b2) / (c2+a2+b2)) + r2a2 + r2b2
=  -(r2a2 + r2b2) + r2a2 + r2b2
=  0

and the inflection point is the point
((-c*zmax - ((-b2*c*zmax)/(a2+b2)))/a,   -(b*c*zmax)/(a2+b2),   zmax)


Point in Spherical Polygon: 

Determining whether a given point is inside or outside a given spherical polygon is rather difficult. Several effective algorithms exist for making the same determination on a plane, but those don't transfer well to the surface of the sphere. In the spheres package we have adapted the "point-at-a-distance" algorithm to work on the sphere for "reasonable" polygons, but it cannot be made absolutely foolproof.

The plane is infinitely large so finding a point outside a given polygon is relatively easy on the plane. One can simply pick (maximumX + 1, maximumY + 1) or, to be really safe, one can pick (maximumX * 10, maximumY * 10) where maximumX and maximumY are the maximum values of the given corner points. Indeed the algorithm is frequently refered to as the point-at-an-infinite-distance algorithm because developers just use the point (infinity, infinity), or substitute some absurdly large number for "infinity", no matter what polygon they are working with.

But the sphere is a closed surface so when you go far enough away from a given point you end up back where you started. Consequently there is no easy way to pick a point known to be external to the polygon. The spheres package employs a number of heuristics to guess an external point as outlined below, and in cases where that guess it likely to be wrong the SphericalPolygon class has a setExternalPoint() method to allow users to designate the known external point.

Given a point known to be external to the polygon determining if a given point is inside a given polygon is a simple matter.

  1. Connect the point to the known external point with a great circle arc.
  2. For each great circle arc that is a side of the spherical polygon test if it intersects the arc constructed in step #1 and count the number of intersections.
  3. If the total number of intersections is odd the given point is inside the spherical polygon. if the total number of intersections is even the point is outside the spherical polygon.

Behavior is undefined if the given point is a corner point of, or on an edge of, the spherical polygon. In cases where the great circle arc constructed in step #1 just touches an edge of the polygon the algorithm may wrongly designate an external point as internal. But those cases should be excessively rare.


Guess External Point: 

For most reasonable spherical polygons finding a known external point is fairly straightforward. A notable exception is a spherical polygon that is intended to outline an orbit of a satellite born sensor. The swath of a single orbit of a sensor on a polar orbiting satellite commonly covers both poles, all longitudes, and all latitudes while covering only a small portion of the Earth's surface. This is precisely why the spheres package includes an Orbit class, and for the purposes of working with spherical polygons it is assumed the polygon does not have these traits.

Another difference between polygons on the plane and polygons on the sphere is that while both merely separate the surface into two distinct areas there is no obvious way to define the "inside" of a spherical polygon. On the plane it is simple, the "inside" is the part with a finite area. But the sphere is a closed surface so both areas are finite. Moreover there is often good reason to define an area on the sphere that covers more than half the sphere.

Nevertheless the spheres package has to make some assumptions which are described below. Because the poles are discontinuities in the spherical coordinate system the spheres package generally avoids using them as an external point.

The spheres package uses the following heuristics to guess an external point.

  1. Check the longitude range. If the longitude range is less than 360 degrees the package assumes the defined area is the one that doesn't include both poles. Then any point with a longitude outside the range of the polygon will do. The spheres package picks a point in the middle of the complement of the longitude range of the polygon, halfway between the extreme latitude of the polygon with the smallest absolute value and the corresponding pole.
  2. Check the latitude range. If the longitude range is the full 360 degrees and the latitude range is completely within either the northern or southern hemisphere the spheres package assumes the defined area is the smaller one. Then any point in the other hemisphere will do. The spheres package arbitrarily picks a longitude of 99.9 for the external point and picks a latitude halfway between the edge of the polygon and the excluded pole.
  3. If the longitude range is the full 360 degrees and the latitude range crosses the equator the package has little to base it's guess on. If the area being defined is "reasonable" then it probably doesn't include both poles, so the spheres package picks the pole that is furthest from the extreme latitude of the polygon with the smallest absolute value.

This is clearly just a guess. One consequence of this guess is that if you are attempting to define an orbit as a polygon, and the swath of the sensor is wide enough to include both poles, the point-in-polygon algorithm will always be wrong because the "external" point is actually internal. If you are trying to use the point-in-polygon method with "unusual" polygons it is best to set your own external point. Polygons that include both poles count as "unusual".


Author: Ross Swick

Please send comments, questions and queries regarding the Spheres project to swick@geospatialmethods.org

Last modified: Mon Oct 14 18:24:51 2002