Title: Some Algorithms for Polygons on a Sphere
1Some Algorithms for Polygons on a Sphere
Robert.G.Chamberlain_at_jpl.nasa.gov William.H.Duquet
te_at_jpl.nasa.gov
- Jet Propulsion Laboratory
- California Institute of Technology
- 4800 Oak Grove Drive
- Pasadena, CA 91109-8099
Association of American Geographers Annual
Meeting San Francisco, CA 1721 April 2007
2Algorithms for Polygons on a Sphere
We are developing a new training simulation for
the Army
- Q Why bother with spherical trig?
- A To avoid implementing a sophisticated
projection - Many other simulations interfaces doomed,
unless - Use spherical coordinates lat and lon
- Algorithms Area, Point-in-Polygon,
Polygon-on-Polygon Area - But a search found only planar algorithms
- What is a straight line?
- Great circle segments, of course
- But political boundaries are rhumb lines!
- KISS Can we just use a straightedge on a plot
of lat vs lon?
- Any of these are okay if the lines are not too
long - How long is too long?
This is aka an equidistant cylindrical,
equirectangular, or Plate-Carée projection
3Preliminaries
- Earth
- Sphere with radius R
- , lat (Latitude), is zero at equator, north is
positive - , lon (Longitude), is zero at Greenwich, east
is positive - Polygon
- Described by counterclockwise sequence of
vertices, numbered from i 0 to N1 thus it has
N sides (edges) - Coordinates of point i are and
- Simply connected (one piece)
- No holes
- No edge crosses or touches another
- Neither pole is inside the polygon
4- The Planimeter
- Algorithm to Compute
- the
- Area of a Polygon
5Area The Planar Algorithm
Area is the sum of signed areas of trapezoids
between the edges and a baseline
1
N 2
polygon
0 or N
2
3
N 1
y
x
baseline
6Area The Planar Algorithm
Positive Area
Polygon is CCW, soright-to-left is a top
edge with a positive area
1
N 2
0 or N
2
3
N 1
y
x
baseline
7Area The Planar Algorithm
More Positive Area
1
N 2
0 or N
2
3
N 1
y
x
baseline
8Area The Planar Algorithm
Negative Area
(Same Formula)
Left-to-right is a bottom edge with a negative
area
1
N 2
0 or N
2
3
N 1
y
x
baseline
9Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
10Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
11Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
12Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
13Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
14Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
15Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
16Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
17Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
18Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
19Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
20Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
21Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
22Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
23Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
24Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
25Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
26Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
27Area The Planar Algorithm
1
N 2
0 or N
2
3
N 1
y
x
baseline
28Area The Planar Algorithm
Note that the coordinates of the baseline
canceled out
1
N 2
0 or N
2
3
N 1
y
x
baseline
29- The
- Area of a Polygon
- on a
- Sphere
30Area The Spherical Case
- Now the baseline is the South Pole and the
- trapezoid is replaced by a spherical triangle.
But a simple exact expression for the areas of
these triangles has eluded us.
31 32Point in Polygon
- Standard algorithm
- Construct a ray from the test point to a point
known to be outside the polygon. (North Pole)
- Compare test ray to each edge in the polygon
- Count the number of edges crossed
- An odd implies the Test Point is inside
- What if the test ray goes through a vertex?
- Count it as crossing both edges? Neither?
- No Vertices that are exactly on the test ray are
all arbitrarily on one side of the ray (East)
Polygon
Test Point
33 34Overlapping Polygons
- What is the area covered by both of two polygons?
- Simple cases
One entirelyinside the other
Non-overlapping bounding boxes
Bounding boxes overlap, but polygons do not
intersect
- Otherwise, add vertices at all intersections
(if needed)
- Mark changes from inside to out and from out to
in as crossings(all intersections are now
vertices, but some might not be crossings)
35Overlapping Polygons
- To find the shared sub-polygons
- Follow the perimeter of one polygon (red) to a
crossing point, starting outside the other
polygon (green) - Remember the starting point (so youll know when
youve checked all the (red) edges)
36Overlapping Polygons
- Unmark the crossing point
- Continue to the next crossing, copying the (red)
edge(s) as the first edge(s) in the shared
sub-polygon - Change to the other (green) polygon
37Overlapping Polygons
- Unmark the crossing point
- Continue to the next crossing, copying the
(green) edge(s) into the shared sub-polygon - Change to the other (red) polygon
38Overlapping Polygons
- Repeat
- Unmark the crossing point, continue to next
crossing point - Copying the (red) edge(s) into the shared
sub-polygon - Change to the other (green) polygon
39Overlapping Polygons
- Repeat
- Until back at the start of the shared sub-polygon
40Overlapping Polygons
- Continue along the (red) polygon to the next
marked crossing point
41Overlapping Polygons
42Overlapping Polygons
43Overlapping Polygons
44Overlapping Polygons
- Until there are no more marked crossing points
45Overlapping Polygons
- Until there are no more marked crossing points
- Use the Area algorithm for each of the
sub-polygons
46- Three Kinds
- of
- Straight Lines
47Three Kinds of Straight Lines
- Those algorithms are topological but
- Crossing requires knowing the shape of the
edges - Great circle segment shortest distance on
surface - Rhumb line most (all?) straight political
boundaries - US Supreme Court 1980 The oblique portion of the
California-Nevada border is SE from a specified
lat, lon (in Lake Tahoe) - How about a straightedge line on a lat-lon plot?
- This lat-lon line is closer to a rhumb line
than a great circle is if the lines are not too
long - The paper gives formulas for lat vs lon, bounding
boxes, and intersection tests for these 3
definitions - Using a northerly ray in the intersection test
simplifies the intersection tests
48 49How Long is Too Long?
- When does it matter which kind of straight line
we use? - Edge Length?
- LAX (Los Angeles) to JFK (New York) is only 1
farther on a rhumb line than on a great circle
segment (2165 nm vs 2144 nm) - Exact lengths can be computed from formulas in
the paper - Area?
- Unless the polygon is extremely gerrymandered,
area has very little dependence on which of
these definitions is used - If polygon is entirely in the Northern or
Southern Hemisphere, errors near the northern
edges will tend to cancel those near the southern - Great circle and lat-lon formulas are in the
paper - Point in Polygon?
- Yes so we looked at the maximum separation
between the three kinds of line - But, back in the application, how big is the
point? If its an M1A1 tank, for example, it is
3 meters wide and almost 10 meters long!
50How Long is Too Long?
North
MaxGC
Great Circle Segment
Rhumb Line
Azimuth
Lat-lon Line
MaximumEdge Length
MaxSL
Latitude
Longitude
- Closed-form expressions for MaxGC and MaxSL are
too complicated to give any insight - The paper gives tables
- Pick how big is a point MaxGC or MaxSL ? which
table - 1, 5, 10, 20, 50, 100, 200, 500 meters
- Select latitude or latitude range of interest ?
which row or rows - If you can select azimuth, do so ? which column
or columns - Then Maximum Edge Length is the cell contents in
the table
51How Long is Too Long?
North
MaxGC
Great Circle Segment
Rhumb Line
Azimuth
Lat-lon Line
MaximumEdge Length
MaxSL
Latitude
Longitude
Example MaxSL10 meters, Latitude 33, Azimuth
62 Maximum Edge Length 38
kilometers
Latitude
42 31 27 25 25 25
27 31 42
50
50 37 32 30 30 30
32 37 50
40
60 44 38 36 36 36
38 44 60
30
72 53 45 43 43 43
46 53 72
0 10 20 30 40 50 60
70 80 90
Azimuth
52How Long is Too Long?
North
MaxGC
Great Circle Segment
Rhumb Line
Azimuth
Lat-lon Line
MaximumEdge Length
MaxSL
Latitude
Longitude
- Example MaxSL10 meters, 30 lt Latitude lt
50,Azimuth unknown Maximum Edge Length 30
kilometers
Latitude
42 31 27 25 25 25
27 31 42
50
50 37 32 30 30 30
32 37 50
40
60 44 38 36 36 36
38 44 60
30
72 53 45 43 43 43
46 53 72
0 10 20 30 40 50 60
70 80 90
Azimuth
53How Long is Too Long? Bottom Line
Great Circle Segment
Rhumb Line
Lat-lon Line
Maximum Edge Length