views:

323

answers:

2

I have a Latitude, Longitude, and a direction of travel in degrees true north. I would like to calculate if I will intersect a line defined by two more Lat/Lon points.

I figure the two points defining the line would create my great circle and my location and azimuth would define my Rhumb line.

I am only interested in intersections that will occur with a few hundred kilometers so I do not need every possible solution.

I have no idea where to begin.

A: 

The simple answer is yes -- if you start from any lat/lon and continue traveling along some great circle, you will eventually cross any and all other great circles on the earth. Every two great circles on earth cross each other in exactly two points (with the notable exception of two identical great circles, which, well, cross each other in all their points.)

But I guess you are not merely asking a yes/no question. You may be wondering where, exactly, those two great circles intersect. We can use the following strategy to find that out:

  1. Each great circle lies on a plane that goes through the center of the earth.

  2. The intersection of those planes is a line (assuming they are not both the exact same plane.)

  3. That intersecting line crosses the surface of the earth at two points -- exactly where our two great circles intersect.

  4. Our mission is thus: (1) find the planes. (2) find their intersection line. (3) find the two intersection points, and finally, (4) express those intersection points in terms of lat/long. (5) extra credit for figuring out which intersecting point is closer to the lat/lon you started at.

Sounds good? The following does this with trig and vector math. To simplify the math somewhat, we'll:

  • work with the unit sphere, the one centered at the origin of our (x,y,z) coordinate system, and has a radius of 1: x^2+y^2+z^2=1.
  • we'll assume the earth is a perfect sphere. Not a geoid. Not even a flattened sphere.
  • we'll ignore elevation.

Step 1 -- find the planes:

All we really care about is the plane normals. Here's how we go and find them:

--One great circle is defined by two points on the earth that it crosses

The normal will be the cross product of the (x,y,z) vectors of each point from the origin (0,0,0). Given the lat/lon of each point, using spherical coordinates conversion, the corresponding (x,y,z) are:

x=cos(lat)*sin(lon)
y=cos(lat)*cos(lon)
z=sin(lat)

With that, and our two points given as lat1/lon1 and lat2/lon2, we can find out the vectors P1=(x1,y1,z1) and P2=(x2,y2,z2).

The first great circle normal is then the cross product:

N1=P1 x P2

--The other great circle is defined by a point on the earth and an azimuth

We have a point P3 and an azimuth T. We'll find a point P4 along the great circle going through P3 at azimuth T at a distance of PI/4 by using the spherical law of cosines (also solved for our convenience here):

lat4=asin(cos(lat3)*cos(T))
lon4=lon3+atan2(sin(T)*cos(lat3),-sin(lat3)*sin(lat4))

Then the normal is as before:

N2=P3 x P4

Step 2: find the planes intersecting line:

Given the two plane normals, their cross product defines their intersecting line:

L=N1 x N2

Step 3: find the intersection points:

Just normalize the vector L to get one of the intersection points on the unit sphere. The other point is on the opposite side of the sphere:

X1=L/|L|
X2=-X1

Step 4: express the intersection points in terms of lat/lon:

Given X=(x,y,z), using spherical coordinate conversion again, and taking into account the point is on the unit sphere:

lat=asin(z)
lon=atan2(y,x)

Step 5: which of the two points is closer?

Use the haversine formula to figure out the distance from your point to X1 and X2, choose the nearer one.

Oren Trutner
I do not think a Great Circle/Great Circle intersection is what I am looking for. I actually already have that implemented. If I am traveling at a constant azimuth would I not spiral around the globe towards one of the poles? At the very least I am picturing myself hypothetically traveling near one of the poles due west and it possibly creating a small circle parallel to the equator. I think I am looking for a Small Circle/Great Circle Intersection or a Ray/Great Circle intersection if it exist.
Karl T
If you travel due true East or due true West, you will circle the globe and come back to your starting point. If you travel on a constant heading some epsilon north or south of true East or true West, but not true North or true South, you will indeed spiral to one of the poles. This is called a "rhumb line" and it was the easy way of doing air navigation back before modern electronic navaids and computers that could plot Great Circles.
John R. Strohm
It wasn't clear from the question that you wanted the azimuth maintained. That indeed would give you a rhumb line path, which is more complicated than a great circle. Unless the distances involved are quite small, you are looking at an infinitely long, pole hugging spiral. The wikipedia page (http://en.wikipedia.org/wiki/Rhumb_line#Mathematical_derivation) has the math describing the rhumb line curve. I don't have the math to solve the GC/rhumb intersection (infinite number of solutions.) A numerical approach would narrow down on the intersection by limiting the search to a (contd.)
Oren Trutner
(contd.) single revolution, and testing for what side of the GC you are by looking at the sign of the dot product of the GC's normal and the point you're testing. http://en.wikipedia.org/wiki/List_of_numerical_analysis_topics#Finding_roots_of_nonlinear_equations lists numerical methods, and Newton's may be simple and fast enough to narrow down on the roots quickly.
Oren Trutner
+2  A: 
brainjam