[Math] How to calculate an intersection point between two coordinates and their bearings

coordinate systemsspherical coordinates

Given two latitude and longitude points, the bearing with respect to north of a great-circle path starting at each point, and the distance between the two points, how can I calculate the latitude and longitude of the intersection of the two paths if it exists?

Best Answer

There is a standard formula for this problem on the Aviation Formulary web page. There are also many other useful formulas on that page.

Now to consider various special cases.

One special case is when the two points are the same. Then the bearing (also known as a course angle) from one point to the other is not well defined. Since the bearing is used in the general algorithm for the intersection, we can't use that algorithm. But the obvious intersection point is the same as the starting point(s).

If either point is at the north or south pole, every path from it has the same bearing from North, so the bearing doesn't actually tell you which path is taken from that point. This special case has to be treated as an error, I think, except perhaps if one point if the north pole and the other is the south pole (in which case you might choose either one as "the" intersection).

The remaining special cases are for two points not the same, neither one at a pole.

If the starting points are antipodes of each other, that is, diametrically opposite each other on the Earth, then each of the paths reaches the other point after traveling half way around the Earth. For example, the point $20$N $30$E is the antipodes of $20$S $150$W. If the initial bearings of the two paths add up to any whole multiple of $\pi$ radians ($180$ degrees), then the two paths travel along the same great circle and there are infinitely many points of intersection. If you must pick one, it could be one of the two starting points or one of the two points midway between them; you could decide by considering the initial bearings at each point.

If the points are not antipodes, it is still possible that the paths from the two points travel along exactly the same great circle. For example, if the two starting points are $20$N $10$E and $40$N $10$E, and both start with bearing $0$ degrees from North, then both paths travel the same great circle in the same direction. Using the same two starting points, if one path starts out at bearing $0$ degrees and the other starts with bearing $180$ degrees, they will travel the same great circle in opposite directions. In either case, the path from each point goes through the other point and eventually circles around the Earth to arrive at its starting point.

One way to tell if the paths travel the same great circle is to look at the bearing or course angle from each point to the other point. If the direction from point $A$ to point $B$ is the same as the given bearing of the path starting at $A$, then that path will pass through both points. If the direction from $A$ to $B$ is exactly opposite the given bearing (a difference of $\pm\pi$ radians or $\pm180$ degrees), the path will still go through both points; you just have to go more than half way around the Earth to reach the other point.

You can write a function to decide whether the given path from $A$ passes through $B$. You can then use the same function to decide whether the path from $B$ passes through $A$. If both paths pass through the other point then they are both on the same great circle. Technically, any point is equally "the" intersection point, so you just need to pick one that makes sense to you: the first point, the second point, a point midway between them, or even the antipodes of the midway point. The choice could depend on whether the initial bearing at each point is directly toward or away from the other point.

In any other case, the paths will intersect in exactly two points. The two intersections are antipodes of each other. If the initial bearings at both points are toward the same point of intersection, I would choose that point as "the" intersection. (The intersection might be up to halfway around the Earth from either starting point.)

But it is possible that each path's initial bearing is toward a different one of the two points of intersection. Then you have to come up with some criteria for picking one point or the other, depending possibly on which point is closer to which intersection. In the application for which I needed this algorithm, this case should not have come up normally, so I arbitrarily decided that "the" intersection point would be the intersection that was first reached by the first path.

Related Question