Compute Angle Between Two Points on a Sphere – Spherical Geometry

anglespheresspherical-geometry

Exist an equation that provide the angle between two points in a sphere.

What I'm looking is not easy to explain, anyway assume to have two points in a sphere than connect this tho points with a line (A and B in the figure) and than how can I compute the angle between the line and a fix reference line or a kind of orientation of reference (as if the two points were in a normal plane)? Is there any way to do something like that?

enter image description here

Best Answer

I'm going to give two answers. The first I'll derive, but it uses some linear algebra, which may not be familiar to you, and converts to "xyz" coordinates to do its work. The second uses just angles, and I'll just give you the formula and a references. Ideas needed:

  1. I'll represent an arrow from the origin $(0,0,0)$ to a point $(a, b, c)$ by writing $[a, b, c]$, and call it a "vector". I call this "the vector corresponding to the point $(a,b,c)$", just to have a name for it.

  2. "cross product of vectors": $[x, y, z] \times [a,b, c] = [yc - zb, za - xc, xb-ya]$. If the two vectors are nonzero and not parallel, then the cross product is a vector perpendicular to both.

  3. "dot product of vectors": $[x, y, z] \cdot [a, b, c] = ax + yb + zc$.

  4. "length of a vector $v = [x, y, z]$: we define $\| v \| = \sqrt{x^2 + y^2 = z^2} = \sqrt{ v \cdot v }.$

  5. If $v$ and $w$ are nonzero vectors, then the angle $\theta$ between then satisfies $ \cos \theta = \frac{v \cdot w} {\|v \| ~ \|w\|}$.

  6. There's a function, $atan2$, in most software packages, that takes a non-origin point point $(x, y)$ of the plane and produces $atan2(x, y)$, which is the angle, measured counterclockwise from the positive $x$-axis, to the ray from $(0,0)$ through $(x, y)$. (It's a lot like "arctan", but gives correct answers for points in the 3rd and fourth quadrant by checking the sign of $x$.)

  7. A vector $[x, y, z]$ represents a point with spherical coordinates, where the "latitude coordinate" $\theta$ is $atan2(x, y)$, and the "longitude coordinate" is $\phi = \cos^{-1} z$. This assumes that the coordinates are set up so that the $xy$ plane is the equatorial plane, and the two "poles" lie at $(0,0,1)$ and $(0,0, -1)$, and that we are measuring in units that make the radius of the sphere "1". Note that the $\phi$ coordinate of a point on the equator is 0, with the phi coordinate being $\pi/2$ (or 90 degrees) a the north pole. If you are used to measuring from $0$ (at the north pole) to $\pi$ (or 180 degrees) at the south pole, you'll need a conversion.

  8. The inverse transformation, from $(\phi, \theta)$ coordinates to $xyz$ is $(x, y, z) = (\cos \theta \sin \phi, \sin \theta \sin \phi, \cos \phi)$.

  9. Points $(x,y,z)$ on the plane $Ax + By + Cz = 0$ (which intersects the unit sphere in a great-circle, because the plane passes through the origin, which is the center of the sphere) can also be described by saying that each point $(x, y, z)$ corresponds to a vector $v = [x, y, z]$ with the property that $n \cdot v = 0$, where $n$ is the vector $[A, B, C]$. We call $n$ "a normal vector for the plane."

I think that's it. :)

Now let's look at your diagram. I'm going to call the center of the sphere $U = (0,0,0)$, just to have a name for it.

The great circle containing $B$ and $C$ lies in a plane that's perpendicular to the vectors $b$ and $c$ for $B$ and $C$. One such vector is $n_1 = b \times c$. The same goes for the great circle through $A$ and $B$. If we say that $a$ is the vector corresponding to $A$, then one normal to the plane of that second great circle is $n_2 = a \times b$.

The cool observation here is that the angle $\theta$ that you're looking for at $B$ is exactly the angle between these two planes...which is also exactly the angle between their normal vectors! And from item 5 above, you can compute this by $$ \theta = \cos^{-1} \left( \frac{n_1\cdot n_2}{\|n_1\|~ \|n_2 \|}\right). $$

So your complete "formula" for computing the angle is this:

  1. Convert each point, $A$, $B$, $C$ in polar coordinates, to rectangular, using item 8, to get coordinate triples that we treat as vectors $a$, $b$, $c$.

  2. Compute $n_1 = b \times c$, $n_2 = a \times b$, using item 2.

  3. Compute $\| n_1 \| $ and $\| n_2 \|$ using item 4, and $n_1 \cdot n_2$ using item 3.

  4. Compute $\theta = \cos^{-1} \left( \frac{n_1\cdot n_2}{\|n_1\|~ \|n_2 \|}\right)$.

That wasn't so bad, was it? :)

In general, the formula for the cosine of the angle at $B$ is

$$ \cos B = \frac{\cos b - \cos a \cos c}{\sin a \sin c} $$ where in this case, I'm using "B" to denote the angle you've drawn at point $B$, but "$b$" to indicate the angle subtended by the points $A$ and $C$ from the origin $U$, and similarly for $a$ and $c$. (You've used these lower-case letters to label three arcs, and I'm just saying that they denote not the length of the arc in miles, but rather the measure of the arc (a number between $0$ and $180$ degrees, or between $0$ and $\pi$ radians).

Computing those subtended angles? I'd be inclined to use rectangular coordinates and dot products as I did before. :)

Also: the angle at "B" is ambiguous: if you pick the angle $\pi + B$, you'll still eventually get to point $A$. If you're writing a program, you may find that the inverse cosine messes you up sometimes because of this.

Most books on celestial navigation derive these formulas, as will any book on spherical trigonometry.

Related Question