0

I have 4 geographic points (latitude, longitude, altitude). By assuming the curvature of the earth, these correspond to two curves. Points A and B make up the end points of the first curve segment. Points C and D make up the end points of the second curve segment.

I want to determine if these two curve segments intersect. I'm assuming the best way to go about this is to convert these four points into Cartesian Coordinates which I've done. But I'm not sure how to solve for the rest. I've seen examples pertaining to two great circles, infinite lines, or line segments. But I haven't been able to put it all together. Anyone have any ideas (or better tags for me)?

alexs973
  • 1
  • 1
  • There are an infinite amount of curves which connect two points on a sphere. Which curves do you mean? Segments of great-circles? – kvantour Jan 07 '20 at 13:54
  • Maybe this is relevant to you? http://www.boeing-727.com/Data/fly%20odds/distance.html – kvantour Jan 07 '20 at 13:57
  • 1
    It's simply not possible to tell without more information. For any four points there will always be a way to connect them by two curves which do intersect, and a different way using two curves which don't intersect. – Especially Lime Jan 07 '20 at 13:58
  • 5
    Does this answer your question? Intersection of two arcs on sphere – kvantour Jan 07 '20 at 13:59
  • These aren't infinite curves, or great circles. They are segments. Points AB make up the end points of the first segment. Points CD make up the endpoints of the second segment. Also @kvantour, yes I mean segments of great circles. Sorry if this wasn't clear – alexs973 Jan 07 '20 at 14:01
  • @alexs973 I assume you also mean the shorter of the two possible ways to connect along a great circle? If so, the curves you're asking about are the geodesics defined by these points. – Especially Lime Jan 07 '20 at 14:06
  • And are you attempting this on a sphere or ellipsoid? – kvantour Jan 07 '20 at 14:13

1 Answers1

0

A great circle is the intersection of the sphere and a plane through the origin. For two great circles, their planes will intersect in a line passing through the center. The two intersection points of the line with the sphere are also the two intersection points of the two great circles.

The only thing remaining to determine is if one of those intersection points is on the arcs $\overset\frown {AB}$ and $\overset\frown {CD}$ instead of their opposite arcs on the great circle. If $\overset\frown {PQ}$ always refer to the shorter of the two great circle arcs generated by non-antipodal points $P$ and $Q$, then an easy trick is that the plane intersection line will intersect the arc $\overset\frown {PQ}$ if and only if it also intersects the chord $\overline{PQ}$.

So you have points $A, B, C, D$, which you've already converted into cartesian coordinates. You don't say what size sphere you've converted them too, but it will be easiest if it is points on the unit sphere. Treat these points as vectors.

  • The normal to the plane of the great circle through $A$ and $B$ is $\vec n = A \times B$ - the vector cross-product. The plane itself has equation $\vec n \cdot \vec r = 0$, where $\vec r$ is the position vector. Similarly, let $\vec m = C \times D$. From a mathematical point of view, it doesn't matter, but it might be wise numerically to replace $\vec n$ and $\vec m$ with their normalized versions: $\hat n = \frac{\vec n}{\|\vec n\|}, \hat m = \frac{\vec m}{\|\vec m\|}$.

  • The line of intersection between these two planes is perpendicular to both normals, which means it must be parallel to their cross-product, so let $\vec v = \hat n \times \hat m$. Again, for numerical stability, it is best to use $\hat v = \frac{\vec v}{\|\vec v\|}$ instead of $\vec v$ itself - though mathematically both will give the same answer. Since this line passes through the origin, it is the set $\{t\hat v\mid t\in \Bbb R\}$.

  • The line segment from $A$ to $B$ is $\{A + s(B - A)\mid s \in [0,1]\}$.

So to find if they intersect, we need to solve $t\hat v = A + s(B - A)$ for $t$ and $s$. As $A, B, \hat v$ are 3-dimensional vectors, this is a system of three linear equations in the two unknowns $s$ and $t$. This system can have $0, 1$ or infinitely many solutions, though the latter can be discounted, as it would require $A$ and $B$ to be antipodes, which would have failed much earlier. If it has no solution, then the two arcs cannot intersect. If there is a unique solution, then look at the value of $s$: if $s < 0$ or $s > 1$, then the line does not intersect $\overline{AB}$ and $\overset\frown {AB}$, so again there is no intersection between the arcs.

If $s \in [0,1]$, the line intersects $\overset\frown {AB}$. Perform the same calculation for $\overset\frown {CD}$. It that $s \in [0,1]$ as well, the line also intersects $\overset\frown {CD}$ - but it may do so on the opposite side of the sphere from the intersection with $\overset\frown {AB}$. So now compare the two values for $t$ obtained from the $\overset\frown {AB}$ and $\overset\frown {CD}$ calculations. If they are of the same sign, then $\overset\frown {AB}$ and $\overset\frown {CD}$ intersect. If they are of opposite sign, they do not intersect.

Paul Sinclair
  • 43,643