Abstract
The algorithms given in Karney (J. Geodesy 87:43–55, 2013), to compute geodesics on terrestrial ellipsoids, are extended to apply to ellipsoids of revolution with arbitrary eccentricity. For the direct and inverse geodesic problems, this entails implementing the formulation in terms of elliptic integrals given by Legendre and Cayley. The integral for the area of geodesic polygons is computed in terms of the discrete sine transform of the integrand. In all cases, accuracy close to full machine precision is achieved. An open-source implementation of these algorithms is available.
Similar content being viewed by others
Avoid common mistakes on your manuscript.
The quantities s, \(\sigma \), \(\lambda \), and \(\omega \) are measured from the node, the point where the geodesic crosses the equator in the northward direction (as in an ascending orbital node). A single subscript refers to a specific point, e.g., \(s_1\) measures the distance from the node to point 1; for s, \(\sigma \), and \(\lambda \), a double subscript denotes a difference, e.g., \(\lambda _{12} = \lambda _2 - \lambda _1\).
1 Introduction
In an earlier paper, Algorithms for geodesics (Karney 2013, henceforth referred to as AG), I presented algorithms for solving geodesic problems on an ellipsoid of revolution. This built on the classic work of Bessel (1825) and Helmert (1880) to give full double precision accuracy for ellipsoids with flattening satisfying \(|f| \le \frac{1}{100}\). (“Double precision” here refers to floating point numbers with 53 bits—about 16 decimal digits—of precision.) A small improvement, described in Appendix A.2, extended this range \(|f| \le \frac{1}{50}\). Perhaps the most consequential innovation of AG was the reliable solution of the inverse geodesic problem, computing the shortest path between two arbitrary points on the ellipsoid. (Previously, the state of the art was provided by Vincenty (1975), which sometimes fails to converge.) Another important advance was turning the formulation of Danielsen (1989) for the area between a geodesic segment and the equator into an algorithm for computing accurately the area of any geodesic polygon, a polygon whose edges are geodesics. These algorithms allow geodesic problems to be reliably solved and this, in turn, has meant that they have been widely adopted in a variety of disciplines.
The present paper seeks to extend the treatment to arbitrary ellipsoid (in this paper, the term “ellipsoid” should be understood to mean “ellipsoid of revolution”, i.e., a “spheroid”). The condition \(|f| \le \frac{1}{50}\) covers all terrestrial applications. However, for the giant planets in our solar system, f lies outside this range (for Saturn, we have \(f\approx \frac{1}{10}\)). For geodesic calculations, the solutions of the direct and inverse problems, this is a matter of realizing the formulation in terms of elliptic integrals, originally given by Legendre, as a usable algorithm. Generalizing the computation of the area of a geodesic polygon required a novel approach using the discrete sine transform.
Although the mathematical techniques used in this paper might be daunting for some readers, the concepts of geodesics with their interlocking definitions in terms of straightest lines and shortest paths are readily grasped. Furthermore, geodesics have well understood properties, for example:
-
The shortest path from a point to a line intersects the line at right angles;
-
Shortest geodesics satisfy the triangle inequality and the other conditions that define a metric space;
-
Consequently, nearest neighbor problems can be solved efficiently using a vantage-point tree (Uhlmann 1991; Yianilos 1993).
It is therefore possible, indeed it might be preferable, to tackle many problems involving geodesics by treating the implementation described here as a reliable “black box.”
The appendices cover various small improvements in the original algorithms given in AG and compare the algorithms presented here with recent work by Nowak and Nowak Da Costa (2022).
2 Geodesics in terms of elliptic integrals
2.1 Formulation of Legendre and Cayley
One of the earliest systematic studies of geodesics on an ellipsoid was given by Legendre (1811, §§126–129) who cast the solution in terms of his elliptic integrals. However, when Bessel later wished to obtain numerical results for the course of a geodesic, he stated “Because the tools to compute these special functions [elliptic integrals] are not yet sufficiently versatile, we instead develop a series solution which converges rapidly because \(e^2\) is so small.” Bessel’s approach, series expansions valid for small flattening, became the mainstay for solving the geodesic problem. For a long time, elliptic integrals continued to be difficult to compute conveniently; for example, Abramowitz and Stegun (1964, Chap. 19) only provides tables for the elliptic integrals for selected values of the modulus and parameter. This obstacle was only removed with the work of Carlson (1995) as we describe below.
Before we give Legendre’s solution, let us review the formulation in terms of the auxiliary sphere; see Fig. 2 of AG. This is a construct used implicitly by Legendre and explicitly by Bessel that maps the path of the geodesic on the ellipsoid onto a great circle on the sphere. The latitude \(\phi \) is mapped to the parametric latitude \(\beta = \tan ^{-1}\bigl ((1-f)\tan \phi \bigr )\), the azimuth \(\alpha \) is preserved, and \(\lambda \) and s are related to the corresponding spherical variables \(\omega \) and \(\sigma \) by (Karney 2011, Appendix A)
Substituting the results from spherical trigonometry,
we obtain
where \(k = e' \cos \alpha _0\). \(J(\sigma )\) is a term appearing in the expressions for the reduced length m and the geodesic scale M; both these quantities, which were introduced by Gauss (1828), describe the behavior of nearby geodesics; see Sect. 3 of AG. In brief, m is the ratio of the final linear separation to the initial angular separation for two nearby geodesics that are initially intersecting; M is the ratio of the final to initial linear separations of two nearby geodesics that are initially parallel. These expressions can be put in the form of Legendre’s elliptic integrals,
where
and \(F(\phi , k)\), \(E(\phi , k)\), and \(\Pi (\phi , \alpha ^2, k)\), are incomplete elliptic integrals (Olver et al. 2010, §19.2(ii)). Equations (7) and (8) are similar to the expressions given by Legendre; the only significant difference is that our formulas involve an imaginary modulus, ik, because we choose our origin for geodesics, \(\sigma = 0\), to be at the node (rather than at the vertex, the point of maximum latitude, which was Legendre’s choice). This is inconsequential because the definitions of the elliptic integrals involve the square of the modulus; furthermore, for prolate ellipsoids, ik is real.
Equations (5) and (8) for \(\lambda \) are inconvenient to use in practice because the integrands are arbitrarily large as the geodesic passes close to a pole leading to a nearly discontinuous change in \(\lambda \). Of course, this is the behavior of great circles as they approach a pole, and it is easily described by spherical trigonometry; see Eq. (12) in AG. It is therefore advantageous to split the expression for \(\lambda \) into two terms, one involving \(\omega \) to describe the basic behavior plus another, proportional to f and involving special functions, to describe the ellipsoidal correction. This can be achieved by integrating
which gives
where the near-singular behavior of \(\lambda \) is captured by \(\omega \) with the difference given by a well behaved integral. This is the starting point for Bessel’s series solution.
Cayley (1870) found a similar way to transform Eq. (8) to give
where
Now, the main contribution to \(\lambda \) is \(\chi \), a variable that behaves similarly to the longitude near a pole, and the elliptic integral is relegated to a correction term; not only is it multiplied by \(e'^2\) but the parameter of the elliptic integral, \(-e'^2\) is also small. This allows the longitude to be computed more accurately. The equivalence of the two expressions for \(\lambda \), Eqs. (8) and (13), follows from Olver et al. (2010, Eq. 19.7.8).
2.2 Numerical evaluation of the elliptic integrals
Carlson (1995) provided high-quality algorithms that allowed symmetric elliptic integrals (Olver et al. 2010, §19.16) to be computed to arbitrary accuracy. Legendre’s elliptic integrals can then be simply evaluated using Olver et al. (2010, §19.25(i)). In our implementation, we also use the amendments to Carlson’s paper given in Olver et al. (2010, §19.36(i)).
With these methods in hand, we review the solutions of the direct and inverse geodetic problems. We first discuss the direct problem, determining the final position \(\phi _2\), \(\lambda _2\) and azimuth \(\alpha _2\), given a starting position \(\phi _1\), \(\lambda _1\), initial azimuth \(\alpha _1\), and distance \(s_{12}\). The starting information allows us to calculate the parameter characterizing the geodesic, \(\alpha _0\). Equations (7) and (13) provide a reliable way to follow a geodesic arbitrarily far given its starting position and initial azimuth. The independent parameter in these equations is \(\sigma \), the arc length on the auxiliary sphere. Because we are given the distance \(s_{12}\) to the second point, we need to invert Eq. (7) to find \(\sigma \) in terms of s. This presents no difficulty; s is a monotonically increasing function of \(\sigma \) so there’s a unique solution and, provided we are sufficiently close to the solution, Newton’s method can be used to obtain an accurate result; the derivative needed for Newton’s method, \(\mathrm ds/\mathrm d\sigma \) is given by Eq. (1). This allows the direct geodesic problem to be solved in the same way as in AG.
Figure 1 illustrates a simple (i.e., non-self-intersecting) closed geodesic on an ellipsoid with \(f = \frac{3}{4}\) or \(b/a=\frac{1}{4}\). This is one of a class of “non-standard” closed geodesics that are neither equatorial nor meridional and which appear for sufficiently oblate ellipsoids, \(a > 2b\) (Klingenberg 1982, §3.5.19).
2.3 Solving the inverse problem
The inverse problem is more challenging. Here, we are given the endpoints \(\phi _1\), \(\lambda _1\) and \(\phi _2\), \(\lambda _2\), and wish to determine the shortest distance \(s_{12}\) and azimuths \(\alpha _1\) and \(\alpha _2\). Because we have no direct way to determine the azimuth at the node, \(\alpha _0\), we must resort to an iterative solution. The traditional method for solving this problem, given by Helmert (1880) and used by Vincenty (1975), is functional iteration which fails to converge in cases where the endpoints are nearly antipodal.
A key contribution of AG was to reduce the determination of \(\alpha _0\) to a simple one-dimensional root-finding problem. I briefly recapitulate the method here. Let us assume we have already dealt with equatorial and meridional geodesics. Equatorial geodesics are those with \(\phi _1 = \phi _2 = 0\) and, for oblate ellipsoids, the additional condition that \(|\lambda _{12}| \le (1-f)\pi \); for these we have \(\alpha _1 = \pm \frac{1}{2}\pi \). Meridional geodesics are those with \(\lambda _{12} = 0\) or \(\pm \pi \) and, for prolate ellipsoids, the additional condition that \(m_{12} \ge 0\); and for these geodesics, we have \(\alpha _1 = 0\) or \(\pm \pi \).
For the remaining, oblique, cases, we can, without loss of generality, specialize to the case
Note that \(\lambda _{12} = 0\) is excluded—this case corresponds to a meridional geodesic; the case \(\lambda _{12} = \pi \) only arises for \(f < 0\) (for \(f \ge 0\) this also corresponds to a meridional geodesic).
For a particular trial azimuth \(\alpha ^*_1\), we solve the hybrid problem: given \(\phi _1\), \(\alpha ^*_1\), and \(\phi _2\), compute the longitude difference \(\lambda _{12}(\alpha ^*_1)\) corresponding to the first intersection of the geodesic with the circle of latitude \(\phi _2\). The solution of the inverse problem is then given by finding \(\alpha ^*_1 = \alpha _1\) which solves
with \(0< \alpha _1 < \pi \). We use \(\alpha _1\) as the control variable for this root-finding problem; this is a more convenient choice than \(\alpha _0\) and, once this is found, we can readily obtain \(\alpha _0\). In AG, we solved this equation using Newton’s method. This converges very rapidly but requires a good starting guess for the solution and this, in turn, required a careful analysis of the case of nearly antipodal endpoints.
This technique worked well with ellipsoids with small flattening. However, in the general case, the starting guess was sometimes sufficiently far from the true solution that Newton’s method failed. Before describing how we might deal with this, let us first review the properties of \(\lambda _{12}(\alpha ^*_1)\). First of all, we have \(\lambda _{12}(0) = 0\) and \(\lambda _{12}(\pi ) = \pi \). Furthermore, with one exception, \(\lambda _{12}(\alpha ^*_1)\) varies continuously so Eq. 17 is guaranteed to have a solution. The exception is illustrated in Fig. 2(a); this is the case with endpoints on the equator for an oblate ellipsoid and \(\lambda _{12}(\alpha ^*_1)\) is discontinuous at \(\alpha ^*_1 = {\textstyle \frac{1}{2}}\pi \). Because equatorial and meridional geodesics have already been handled, this only occurs for \({(1-f)\pi }< \lambda _{12} < \pi \) and we can restrict the possible range of azimuth to \({\textstyle \frac{1}{2}}\pi< \alpha ^*_1 < \pi \). Within this range, \(\lambda _{12}(\alpha ^*_1)\) is continuous and a solution exists. Finally, there is exactly one root and hence the derivative \(\mathrm d\lambda _{12}(\alpha ^*_1)/\mathrm d\alpha ^*_1 = \lambda _{12}'(\alpha ^*_1)\) is non-negative at that root. In this context, it is important to consider the case of a prolate ellipsoid; see Fig. 2(b). Even though \(\lambda _{12}(\alpha ^*_1)\) has an interior maximum, \(\lambda _{12}(\alpha ^*_1) = \lambda _{12}\) still has only a single root provided that \(\lambda _{12} \le \pi \) (stipulated in the initial setup of the inverse problem) and that \(\alpha _1 < \pi \) (because we have already handled meridional geodesics).
With this background, even the crudest root-finding techniques, e.g., bisection or regula falsi, can be used to find the solution. We shall continue to use Newton’s method on account of its rapid convergence. However, we back it up with the bisection method to deal with two possible problems with Newton’s method: (a) \(\lambda _{12}'(\alpha ^*_1)\) is so small that the new value of \(\alpha ^*_1\) is outside the range \((0,\pi )\) or (b) \(\lambda _{12}'(\alpha ^*_1)\) is negative, in which case the new value of \(\alpha ^*_1\) is further from the true root. During the course of the Newton iteration, we maintain a bracketing range for \(\alpha _1 \in (\alpha _{1-}, \alpha _{1+})\). Initially, we have \(\alpha _{1-} = 0\), \(\alpha _{1+} = \pi \). On each iteration, we update one of \(\alpha _{1\pm }\) to \(\alpha ^*_1\) depending on the sign of \(\lambda _{12}(\alpha ^*_1) - \lambda _{12}\) provided that this results in a tighter bracket for \(\alpha _1\). Whenever either of the problems, (a) or (b) listed above, occurs, we restart Newton’s method with a new starting guess \(\alpha ^*_1 = {\textstyle \frac{1}{2}}(\alpha _{1-} + \alpha _{1+})\); and we will be able to bisect the bracket after the next iteration.
We can use the spherical solution to get a starting value for \(\alpha ^*_1\) with a value of 0 or \(\pi \) (i.e., outside the allowed range for \(\alpha _1\)) replaced by \(\frac{1}{2}\pi \). (See also Appendix A.3 for additional caveats for the case of equatorial endpoints.) Typically, the bisection safety mechanism is invoked at most once when solving the inverse problem. The net result is that this provides a reliable (always converging) and fast (rapidly converging) method of solving the inverse geodesic problem for arbitrary ellipsoids. In some cases, the inverse problem does not have a unique solution—there are multiple shortest geodesics; these cases are readily handled as discussed in Appendix A.1.
3 The area integral
3.1 Formulation of Danielsen
In AG, \(S_{12}\) was defined as the area between a geodesic segment \(s_{12}\) and the equator, i.e., the area of the geodesic quadrilateral \(AF\!H\!B\) in Fig. 1 of AG. Following Danielsen (1989), this was cast as an integral as follows:
where
is the authalic radius squared, and
This is a change from the notation in Eq. (59) of AG; the relationship is
this simplifies the assessment of the error in \(S_{12}\). The expression \(\Delta t(x,y)\) is the divided difference of t(x). In the limit \(y \rightarrow x\), we have \(\Delta t(x,x)=t'(x)\). If x and y are distinct and have the same sign, there is a systematic way to express \(\Delta t(x,y)\) in a form that avoids excessive roundoff errors (Kahan and Fateman 1999).
The area of an arbitrary geodesic polygon is easily computed by summing the signed area contributions \(S_{12}\) for each edge. An adjustment to this total needs to be made if the polygon encircles a pole as described in AG.
The challenge is that the integral, Eq. (20), cannot be carried out in closed form. However, both \(q(\sigma )\) and \(p(\sigma )\) are periodic functions and so may be written as Fourier series:
Here, Eqs. (26) and (27) constitute a Fourier transform pair. In the next sections, we explore two ways to compute \(P_l\) approximately.
3.2 Using a Taylor series
In AG, we gave Taylor series expansions for \(P_l\) using \(e'^2\) and \(k^2\) as small parameters. For reasons explained in Appendix A.5, this is a poor choice of expansion parameters for eccentric ellipsoids; so we replace the expansion parameters by n and \(\epsilon \), Eqs. (43), resulting in the expansion Eqs. (44) which should be used instead of AG’s Eqs. (63). This expansion may be used to approximate \(p(\sigma )\) with
where \(A_4\) is defined in Eq. (22) and the superscript (N) gives the order at which the Taylor series is truncated; thus Eqs. (44) with the ellipses dropped corresponds to \(N=6\). \(A_4\) is proportional to \(e^2\), so the highest-order terms in Eqs. (44) are \(O(f^6)\); furthermore, we have \(\tilde{P}_l^{(N)} = 0\) for \(l\ge N\).
One possibility for computing the area on eccentric ellipsoids is extending the Taylor series expansion to higher order. Thus, when I first implemented the solution of the geodesic problem in terms of elliptic integrals as described in Sect. 2, I computed the area using \({\tilde{p}}^{(30)}(\sigma )\); this gives full double precision accuracy for \({\textstyle \frac{1}{2}}\le b/a \le 2\). However, this approach quickly becomes cumbersome for extremely eccentric ellipsoids:
-
The value of N required to give full accuracy becomes very large;
-
The cost of determining the coefficients in the Taylor series becomes impractical—it takes Maxima (2022) 17 min for \(N=32\) (tolerable for generating code) but 19 h to extend this to \(N=64\) (which is starting to get prohibitive);
-
The storage required for the coefficients becomes excessive, scaling as \(N^3/6\);
-
Once the ellipsoid is selected, evaluating the coefficients of \(\epsilon ^j\) in Eqs. (44) requires \(O(N^3)\) operations;
-
Once \(\alpha _0\) is given, evaluating \({\tilde{P}}_l^{(N)}\) requires \(O(N^2)\) operations.
3.3 Quadrature using discrete sine transforms
To overcome the shortcomings of Taylor series for large eccentricities, I explored evaluating Eq. (20) using the quadrature method of Clenshaw and Curtis (1960). Given a definite integral,
this method entails expanding g(x) as Chebyshev polynomials, or, equivalently, \(g(\cos \theta )\) as a Fourier series. This allows the definite integral to be computed to high accuracy and, as a bonus, the indefinite integral can be computed. The accuracy is a result of the fast convergence of the trapezoidal rule for integrals of a periodic function over a full period; in this case, the integrals give the Fourier coefficients.
However, this is a roundabout procedure given that we are starting with a periodic function. Instead, we directly evaluate Eq. (27) using the trapezoidal rule and evaluate \(p(\sigma )\) by using the resulting Fourier coefficients in Eqs. (28) and (29). Thus, we approximate \(Q_l\) with
where \(h_N = \pi /(2N)\), we take \(0 \le l < N\), and the prime on the summation sign indicates that the last term in the sum should be halved. Because \(q(\sigma )\) is an analytic periodic function, \({\hat{Q}}_l^{(N)}\) converges to the true value \(Q_l\) faster than any power of N, as \(N\rightarrow \infty \). Equation (32) is, in fact, the discrete sine transform, DST, of type III (Wang and Hunt 1985). Its inverse is a type II DST,
this holds for all integer j. Rewriting this as a continuous function,
we see that \({\hat{q}}^{(N)}(\sigma )\) is likely to be an excellent approximation to \(q(\sigma )\) given that the functions coincide wherever \(\sigma \) is a multiple of \(h_N\). In the same way, we approximate \(p(\sigma )\) by
A convenient way to compute DSTs is using the fast Fourier transform, FFT (Cooley and Tukey 1965). This reduces the cost of evaluating Eq. (32) for \(0\le l <N\) from \(O(N^2)\) to \(O(N\log N)\). Furthermore, Gentleman (1972) points out that the FFT results in smaller roundoff errors compared with other methods. Equation (35) can be evaluated using Clenshaw (1955) summation; this method is fast (the cosine terms are computed by a recurrence relation) and because \({\hat{Q}}_l^{(N)}\) decays rapidly with l and because the summation starts at high values of l, it is also accurate.
As we shall see, the error \(\max (| {\hat{q}}^{(N)}(\sigma ) -q(\sigma ) |)\) decays exponentially with N; thus doubling N roughly squares the error. Furthermore, it is possible to double N rather inexpensively. First, generate the type IV DST for \(q(\sigma )\),
The sums for computing \({\hat{Q}}_l^{(N)}\), Eq. (32), and \({\check{Q}}_l^{(N)}\) involve evaluating \(q(\sigma )\) at intervals of \({\textstyle \frac{1}{2}}h_N = h_{2N}\); it follows that \({\hat{Q}}_l^{(2N)}\) is just the mean of \({\hat{Q}}_l^{(N)}\) and \({\check{Q}}_l^{(N)}\). These coefficients for \(N\le l < 2N\) are
Thus, \({\hat{Q}}_l^{(2N)}\) is given by
for \(g = \frac{1}{2}, \frac{3}{2}, \ldots , N - \frac{1}{2}\). This method avoids wasting the results \({\hat{Q}}_l^{(N)}\) which have already been computed (Gentleman 1972).
3.4 Convergence of approximate Fourier series
In assessing how well \({\hat{p}}^{(N)}(\sigma )\), Eq. (35), approximates \(p(\sigma )\), we start by looking at the error in the individual Fourier coefficients, namely \(\delta {\hat{P}}_l^{(N)} = | {\hat{P}}_l^{(N)} - P_l |\) for a given N. For illustrative purposes, we consider \(b/a = \frac{1}{4}\), \(\alpha _0 = \frac{1}{4} \pi \), and consider \(N = 30\); we compute the “exact” \(P_l\) using a much larger value N. The resulting errors \(\delta {\hat{P}}_l^{(30)}\) are shown in Fig. 3 as crosses. The figure also shows \(|P_l|\) (the solid line) decaying exponentially as a function of l. Obviously \(\delta {\hat{P}}_l^{(30)}\), which equals \(|P_l|\) for \(l\ge 30\), shows the same exponential decay. However, we also have exponential decay in \(\delta {\hat{P}}_l^{(30)}\) as l decreases from 29 to 0; indeed, \(\delta {\hat{P}}_l^{(30)}\) is roughly symmetric about \(l = 30\). This behavior is predicted by Eq. (39), since we can approximate \(\delta {\hat{P}}_l^{(N)}\) by \(|{\hat{P}}_l^{(N)} - {\hat{P}}_l^{(2N)}|\), with
the variation of the numerator in this expression (symmetric in g) is much stronger than the variation of the denominator. We conclude that the error arising from using approximate Fourier coefficients, \({\hat{P}}_l^{(N)}\) instead of \(P_l\), is approximately the same as the error from truncating the Fourier sum in Eq. (35).
Figure 3 also shows the errors in the Taylor series coefficients \(\delta {\check{P}}_l^{(N)} = |{\check{P}}_l^{(N)} - P_l|\) for \(N=30\) as squares. The error is, of course, the same as for \(\delta {\hat{P}}_l^{(30)}\) for \(l \ge 30\); but for \(l < 30\), the error is several orders of magnitude bigger.
Figure 3 gives the errors in the individual Fourier coefficients for a particular N. To gauge how the overall error in \({\hat{p}}^{(N)}(\sigma )\), Eq. (35), varies with N, we combine the errors in the coefficients, as follows:
We similarly define \(\Delta {\tilde{P}}^{(N)}\) for the coefficients obtained by Taylor expansion. Figure 4 shows how these error metrics vary as N is increased from 10 to 60 for \(b/a = \frac{1}{4}\) and \(\alpha _0 = \frac{1}{4}\pi \) (the same parameters used for Fig. 3). Both show exponential decay with \(\Delta {\hat{P}}^{(N)}\) being several orders of magnitude smaller and decaying at a slightly faster rate.
3.5 Determining the number of points in the quadrature
In practical applications, we will evaluate the area using Eqs. (18) and have to contend both with truncation errors, because we use a finite value of N in computing \(p(\sigma )\), and with roundoff errors, because of the limited precision of the floating point number system. We would like to pick N large enough that the truncation errors are less than the roundoff errors, and for this, we require that \(\Delta {\hat{P}}^{(N)} \le 2^{-m}\) where m is the number of bits in the fraction of a floating point number. For double precision, we typically have \(m = 53\) and, substituting the value of \(c\approx 6371\,\textrm{km}^2\) for the earth, this gives a truncation error in \(S(\sigma )\) of \(2^{-53}c^2 \approx 50\,\textrm{cm}^2\). The horizontal line in Fig. 4 labels this error threshold, \(2^{-53}\). This shows that for this case, we need \(N\ge 34\) for the DST method compared to \(N\ge 56\) when using a Taylor expansion.
In principle, we could reestimate N for each geodesic, i.e., for every n and \(\alpha _0\). (Since we are dealing with both oblate and prolate ellipsoids of arbitrary eccentricity, we use n as the measure of eccentricity instead of \(e = 2\sqrt{n}/(1+n)\) or \(f = 2n/(1+n)\).) However, that would require extra machinery to do the estimation at run time. Instead, we estimate N for \(-0.99 \le n \le 0.99\). For a particular n, we find the minimum N that satisfies the accuracy requirement for all \(\alpha _0\). The result is shown in Fig. 5 as the heavy line. The light line shows the result of restricting the allowed values of N to \(2\times 2^j\) and \(3\times 2^j\) with integer \(j \ge 1\); now, N is the product of small factors (2 and 3), a requirement for the efficient implementation of the FFT. The light line is converted to a simple table allowing N to be looked up at run time based on the value of n.
The conclusion is that the discrete sine transform method provides a convenient and accurate way to evaluate the area integral. In comparison with the Taylor series method: the same accuracy is obtained with substantially fewer terms (\(N = 34\) for the DST versus \(N = 56\) for the Taylor series in the example illustrated in Fig. 4). Just as important, N can be easily adjusted for a particular n, Fig. 5 (no need to compute a new Taylor series), the memory required is O(N) instead of \(O(N^3)\), and the setup time for a particular geodesic is \(O(N\log N)\) instead of \(O(N^3)\).
4 Implementation
The algorithms detailed in Sects. 2 and 3 have been implemented in version 2.1.2 of the open-source C++ library, GeographicLib (Karney 2022). The solution of the geodesic problems in terms of elliptic integrals was added in version 1.25 (2012). At that time, the area was computed with a 30th-order Taylor series as described in Sect. 3.2. This was replaced by the implementation using DSTs, Sect. 3.3, in version 2.1 (2022). These algorithms supplemented the earlier ones described in AG since, as we see below, these remain the preferred methods for terrestrial ellipsoids.
We use the KISS FFT package (Boergerding 2021) for performing the DST. Even though this package has no direct support for the DSTs, as a “header-only” package, it is easier to integrate into GeographicLib than the more capable FFTW package (Frigo and Johnson 2021).
The main geodesic calculations are also exposed with two utility programs provided with GeographicLib, GeodSolve for geodesic calculations, and Planimeter for measuring the perimeter and area of geodesic polygons. With both utilities, the -E flag uses the algorithms described here for arbitrary ellipsoids.
In developing numerical algorithms, especially those that offer high accuracy, it is very useful to be able to distinguish truncation errors from roundoff errors. For this reason, high precision calculations were added to GeographicLib in version 1.37 (2014). This allowed the library to be compiled with various alternatives to standard double precision (53 bits of precision or 16 decimal digits) for floating point numbers:
-
Extended precision (64 bits or 19 decimal digits) available as the “long double” type on some platforms;
-
Quadruple precision (113 bits or 34 decimal digits) using the boost multi-precision library (Maddock and Kormanyos 2022);
-
Arbitrary precision (selected at the start of execution) using the MPREAL C++ interface (Holoborodko 2022) to the MPFR library (Fousse et al. 2007).
The results in Figs. 3, 4, and 5 and in Tables 1 and 2 were computed with the last option setting the precision to 256 bits (77 decimal digits).
5 Results
A starting point for testing the new algorithms is the test data set given in Karney (2010). This is specific to the WGS84 ellipsoid and as such allows us to compare the new algorithms with the series solutions described in AG. The maximum errors in geodesic calculations when converted to a distance are about \(0.03\,\mu \mathrm m\) which is 2–3 times larger than the corresponding figures for the series solution. The error in the area is about \(0.1\,\mathrm m^2\) in both cases. On this data set, the new routines run about 2.5 times slower. The lower accuracy and speed are to be expected given the additional complexity of the new algorithms.
The lesson is clear: For terrestrial ellipsoids, the algorithms described in AG are to be preferred—they are faster and more accurate than the new routines. In fact, the new routines are still very accurate and fast. Once the eccentricity of the ellipsoid is such that \(|f| > \frac{1}{50}\), the accuracy of the series solution degrades, and the new routines should be used. Let us, therefore, turn to assessing their performance on eccentric ellipsoids.
We start by considering the geodesic that starts on the equator, i.e., at its node \(\phi _1 = 0\), with azimuth \(\alpha _0 = \alpha _1 = \frac{1}{4}\pi \) and compute the longitude at the vertex (the point of maximum latitude), the distance to the vertex, and the area under this geodesic segment. We shall carry out this calculation with various values of the third flattening n. The arc length on the auxiliary sphere, in this case, is \(\sigma _{12} = {\textstyle \frac{1}{2}}\pi \), and, because \(\tan \alpha _0 = 1\), we have \(\tan \phi _2 = (1+n)/(1-n)\).
The results are shown in Tables 1 and 2 for oblate and prolate ellipsoids, respectively. For each n, the first row shows the results with high precision arithmetic rounded to 17 decimal digits. These allow independent verification of the algorithms. The second row shows the results of carrying out the calculation in double precision. In all cases, the roundoff errors are very small—the changes take place in no more than the last 5 bits of the fraction of the binary representation; with \(|n| \le 0.9\), the errors amount to at most 7 units in the last place in the binary representation.
A more challenging test is presented with the data for the administrative boundaries of Poland. (This was kindly provided to me in 2013 by Paweł Pȩdzich of the Warsaw University of Technology.) This set includes a polygonal representation of the boundary of Poland itself. This consists of \(67\,801\) edges with mean length \(53\,\mathrm m\), minimum length \(62\,\textrm{mm}\), and maximum length \(9.7\,\textrm{km}\); the perimeter of the polygon is about \(3\,600\,\textrm{km}\) and its area is about \(313\,000\,\textrm{km}^2\). This is a good test for geodesic algorithms as it represents a realistic “large” problem allowing the overall accuracy and speed of the algorithms to be assessed.
In performing tests on ellipsoids with varying eccentricities, we need to stipulate how the points are mapped onto the ellipsoid. If we merely keep the latitude fixed, then for extreme oblate, resp. prolate, ellipsoids, all the points end up concentrated near the equator, resp. the poles, making it difficult to interpret the results. We instead map the points keeping the authalic latitude fixed. If, in addition, we choose a so that the area of the ellipsoid matches that of the Earth, the area of the polygon is nearly constant as n is varied, and we assess the errors by computing the difference between the computed area and the true area. For this exercise, we find the true area using quadruple precision arithmetic.
The errors in the area and the perimeter are shown in Fig. 6. Generally speaking, the errors in the area are between \(1\,\mathrm m^2\) and \(10\,\mathrm m^2\) and the errors in the perimeter are between \(1\,\mu \mathrm m\) and \(3\,\mu \mathrm m\).
The elapsed time for these calculations is approximated by
where the first term represents the time to compute the perimeter of the polygon, which involves solving the inverse geodesic problem for an edge, and the second term is the additional time required to compute its area. Here, N is the number of terms used in the DST which is given in Fig. 5. The time to compute the area begins to dominate for \(|n| > 0.2\). The area calculation could be made faster if the DSTs were computed using the FFTW package instead of KISS FFT.
6 Discussion
In this paper, we have shown how to solve geodesic problems on an ellipsoid of arbitrary eccentricity and an implementation of these methods is available in GeographicLib. The work naturally divides into two parts:
The method of solving the standard direct and inverse problems was an exercise in applying Carlson’s algorithms for the evaluation of elliptic integrals to the work of Legendre and Cayley. These then replaced the Taylor series expansions for the elliptic integrals used in AG. In addition, the method for solving the inverse problem needed to be adjusted to ensure convergence in all cases.
The evaluation of the area integral, Eq.(20), is simplicity itself: write the periodic integrand as a Fourier series, evaluate the Fourier coefficients by trapezoidal quadrature, and then the integral of the resulting series is trivial. This is an accurate and fast method because (1) the Fourier series of an analytic function converges rapidly, (2) quadrature is very accurate when applied to the full period of a periodic function, (3) the FFT can be used to evaluate all the coefficients efficiently. This method will be useful in other applications, e.g., to evaluate the Abelian integrals appearing in the solution given by Jacobi (1839) for geodesics on a triaxial ellipsoid.
The algorithms have been tested for a wide range of eccentricities, \(|n| \le 0.99\) or \(1/199 \le b/a \le 199\); this encompasses ellipsoids flatter than a pancake and as thin as spaghetti. In principle, the methods would work at more extreme eccentricities; however, it is likely a more specialized approach would be better in these cases. Despite this, the Taylor series method described in AG is preferred for small flattening, \(|f| \le \frac{1}{50}\). This is somewhat more accurate and somewhat faster than the general method given here.
The obvious domain of application for these algorithms is studying planets and other celestial bodies with high eccentricity. But, they also play a role in terrestrial applications. First of all, they allow the errors in the Taylor series method to be measured accurately. Secondly, because the flattening of terrestrial ellipsoids is so small, a starting approximation to the solution is given by spherical trigonometry and this solution can be subsequently refined using ellipsoidal geodesics. Unfortunately, any specifically ellipsoidal behavior might be overlooked, precisely because the flattening is small. Therefore, it behooves the developer to test the algorithms on more eccentric ellipsoids, say, with \(f = \frac{1}{5}\), because then any ellipsoid effects will be much more apparent.
I should point out an alternative method of treating arbitrary eccentricity, namely to integrate the ordinary differential equations for the geodesic numerically. This is the approach taken by Panou and Korakitis (2017), and it has the advantage that it can be generalized to more complex bodies, e.g., a triaxial ellipsoid (Panou and Korakitis 2019). However, for the problem at hand, our approach is preferable: it is fast, it provides high accuracy, the computation time is independent of the length of the geodesic, and it gives the solution of the inverse problem. For bodies that are well-approximated by a triaxial ellipsoid, an attractive approach would be to recast the solution of Jacobi (1839) into a workable numerical algorithm; however, this (non-trivial!) task is beyond the scope of the present paper.
Data Availability
The data used to compute the area of Poland in Sect. 5 is available upon request.
Code availability
An implementation of the algorithms given in this paper is available in GeographicLib, version 2.1.2, available at https://github.com/geographiclib/geographiclib/releases/tag/r2.1.2.
Abbreviations
- a :
-
Equatorial radius of the ellipsoid
- b :
-
Its polar semi-axis
- f :
-
\((a-b)/a\), the flattening
- n :
-
\((a-b)/(a+b)\), the third flattening
- e :
-
\(\sqrt{a^2-b^2}/a\), the eccentricity
- e \(^\prime \) :
-
\(\sqrt{a^2-b^2}/b\), the second eccentricity
- \(\phi \) :
-
Geodetic latitude, north positive
- \(\lambda \) :
-
Longitude, east positive
- \(\alpha \) :
-
Azimuth of the geodesic, clockwise from north
- \(\alpha _0\) :
-
Azimuth at the node
- s:
-
Distance along the geodesic
- \(\beta \) :
-
Parametric latitude; \(a\tan \beta = b\tan \phi \)
- \(\omega \) :
-
Longitude on the auxiliary sphere
- \(\sigma \) :
-
Arc length on the auxiliary sphere
- c :
-
The authalic radius
- S :
-
The area between the geodesic and the equator
References
Abramowitz M, Stegun IA (eds) (1964) Handbook of mathematical functions. NBS, http://numerical.recipes/aands
Bessel FW (1825) The calculation of longitude and latitude from geodesic measurements. Astron Nachr 331(8):852–861. https://doi.org/10.1002/asna.201011352
Boergerding M (2021) KISS FFT. https://github.com/mborgerding/kissfft
Carlson BC (1995) Numerical computation of real or complex elliptic integrals. Numer Algorithms 10(1):13–26. https://doi.org/10.1007/BF02198293
Cayley A (1870) On the geodesic lines on an oblate spheroid. Phil Mag 40(268):329–340. https://doi.org/10.1080/14786447008640411
Clenshaw CW (1955) A note on the summation of Chebyshev series. Math Comp 9(51):118–120. https://doi.org/10.1090/S0025-5718-1955-0071856-0
Clenshaw CW, Curtis AR (1960) A method for numerical integration on an automatic computer. Num Math 2(1):197–205. https://doi.org/10.1007/BF01386223
Cooley JW, Tukey JW (1965) An algorithm for the machine calculation of complex Fourier series. Math Comp 19(90):297–301. https://doi.org/10.1090/S0025-5718-1965-0178586-1
Danielsen JS (1989) The area under the geodesic. Surv Rev 30(232):61–66. https://doi.org/10.1179/003962689791474267
Fousse L, Hanrot G, Lefèvre V, et al (2007) MPFR: a multiple-precision binary floating-point library with correct rounding. ACM TOMS 33(2):13:1–15. https://doi.org/10.1145/1236463.1236468
Frigo M, Johnson SG (2021) FFTW, version 3.3.10. https://fftw.org
Gauss CF (1828) General investigations of curved surfaces of 1827 and 1825. Princeton Univ. Lib., 1902, https://books.google.com/books?id=a1wTJR3kHwUC, translated by Morehead J C and Hiltebeitel A M
Gentleman WM (1972) Implementing Clenshaw–Curtis quadrature, II computing the cosine transformation. Comm ACM 15(5):343–346. https://doi.org/10.1145/355602.361311
Helmert FR (1880) Mathematical and physical theories of higher geodesy, vol 1. Aeronautical chart and information center, St. Louis, 1964, https://doi.org/10.5281/zenodo.32050
Holoborodko P (2022) MPFR C++ (MPREAL), version 3.6.9. https://github.com/advanpix/mpreal
Jacobi CGJ (1839) Note von der geodätischen Linie auf einem Ellipsoid und den verschiedenen Anwendungen einer merkwürdigen analytischen Substitution. J Crelle 19:309–313. https://doi.org/10.1515/crll.1839.19.309
Kahan WM, Fateman RJ (1999) Symbolic computation of divided differences. SIGSAM Bull 33(2):7–28. https://doi.org/10.1145/334714.334716
Karney CFF (2010) Test set for geodesics. data set, Zenodo. https://doi.org/10.5281/zenodo.32156
Karney CFF (2011) Geodesics on an ellipsoid of revolution. Tech rep SRI Int https://doi.org/10.48550/arXiv.1102.1215
Karney CFF (2013) Algorithms for geodesics. J Geodesy 87(1):43–55. https://doi.org/10.1007/s00190-012-0578-z
Karney CFF (2022) GeographicLib, version 2.1.2. https://geographiclib.sourceforge.io/C++/2.1.2
Klingenberg WPA (1982) Riemannian geometry. de Gruyer, Berlin
Legendre AM (1811) Exercices de Calcul Intégral sur divers ordres de transcendantes et sur les quadratures, vol 1. Courcier, Paris, https://lillonum.univ-lille.fr/s/lillonum/ark:/72505/bjZbcq
Maddock J, Kormanyos C (2022) Boost multiprecision library, version 1.79.0. https://www.boost.org
Maxima (2022) A computer algebra system. version 5.46.0. https://maxima.sourceforge.io
Nowak E, Nowak Da Costa J (2022) Theory strict formula derivation and algorithm development for the computation of a geodesic polygon area. J Geodesy 96(4):20:1–23. https://doi.org/10.1007/s00190-022-01606-z
Olver FWJ, Lozier DW, Boisvert RF et al (eds) (2010) NIST handbook of mathematical functions. Cambridge University Press, Cambridge
Panou G, Korakitis R (2017) Geodesic equations and their numerical solutions in geodetic and Cartesian coordinates on an oblate spheroid. J Geod Sci 7(1):31–42. https://doi.org/10.1515/jogs-2017-0004
Panou G, Korakitis R (2019) Geodesic equations and their numerical solution in Cartesian coordinates on a triaxial ellipsoid. J Geod Sci 9(1):1–12. https://doi.org/10.1515/jogs-2019-0001
Uhlmann JK (1991) Satisfying general proximity/similarity queries with metric trees. Inform Process Lett 40(4):175–179. https://doi.org/10.1016/0020-0190(91)90074-r
Vincenty T (1975) Direct and inverse solutions of geodesics on the ellipsoid with application of nested equations. Surv Rev 23(176):88–93. https://doi.org/10.1179/sre.1975.23.176.88
Wang Z, Hunt BR (1985) The discrete \(W\) transform. App Math Comp 16(1):19–48. https://doi.org/10.1016/0096-3003(85)90008-6
Yianilos PN (1993) Data structures and algorithms for nearest neighbor search in general metric spaces. In: Proceeding of 4th ACM-SIAM symposium on discrete algorithms. SIAM, pp 311–321, https://dl.acm.org/doi/10.5555/313559.313789
Funding
Open access funding provided by SCELC, Statewide California Electronic Library Consortium. No funds, grants, or other support was received.
Author information
Authors and Affiliations
Corresponding author
Ethics declarations
Conflict of interest
The author has no conflict of interest.
Appendices
A Addenda to Karney (2013)
1.1 A.1 Multiple shortest geodesics
The shortest distance found by solving the inverse problem is (obviously) uniquely defined. However, in some special cases, multiple azimuths yield the same shortest distance. Here is a catalog of those cases:
-
\(\phi _1 = -\phi _2\) (with neither point at a pole): If \(\alpha _1 = \alpha _2\), the geodesic is unique. Otherwise, there are two geodesics and the second one is obtained by setting \([\alpha _1,\alpha _2] \leftarrow [\alpha _2,\alpha _1]\), \([M_{12},M_{21}] \leftarrow [M_{21},M_{12}]\), and \(S_{12} \leftarrow -S_{12}\). (This occurs when \(\lambda _{12}\) is close to \(\pm 180^\circ \) for oblate ellipsoids.)
-
\(\lambda _{12} = \pm 180^\circ \) (with neither point at a pole). If \(\alpha _1 = 0^\circ \) or \(\pm 180^\circ \), the geodesic is unique. Otherwise, there are two geodesics and the second one is obtained by setting \([\alpha _1,\alpha _2] \leftarrow [-\alpha _1,-\alpha _2]\), \(S_{12} \leftarrow -S_{12}\). (This occurs when \(\phi _2\) is close to \(-\phi _1\) for prolate ellipsoids.)
-
Points 1 and 2 are at opposite poles: There are infinitely many geodesics that can be generated by setting \([\alpha _1,\alpha _2] \leftarrow [\alpha _1,\alpha _2] + [\delta ,-\delta ]\), for arbitrary \(\delta \). (For spheres, this prescription applies when points 1 and 2 are antipodal.)
-
\(s_{12} = 0\) (coincident points): There are infinitely many geodesics that can be generated by setting \([\alpha _1,\alpha _2] \leftarrow [\alpha _1,\alpha _2] + [\delta ,\delta ]\), for arbitrary \(\delta \).
In cases where there are multiple shortest geodesics, GeographicLib returns an arbitrary one. The list given above allows the user (a) to determine whether there are other shortest geodesics and (b) to generate them.
1.2 A.2 Refining the result from the reverted distance series
The sixth-order series given in AG provide solutions for the geodesic problem which are accurate to roundoff for \(|f| \le \frac{1}{100}\). The least accurate of the series is the reverted series for \(\sigma \) in terms of the scaled distance \(\tau \), Eqs. (20) and (21) of AG, which is used only in solving the direct problem. (This series also gives the reduced latitude \(\beta \) in terms of the rectifying latitude \(\mu \).) The accuracy is improved by using these equations to give an initial approximation for \(\sigma \) which is followed by one step of Newton’s method applied to Eq. (4), with \(\mathrm ds/\mathrm d\sigma = b\sqrt{1 + k^2 \sin ^2\sigma }\). With this change (which need only be applied for \(|f| > \frac{1}{100}\)), the sixth-order series are accurate to roundoff for \(|f| \le \frac{1}{50}\).
1.3 A.3 Non-equatorial geodesics
Care needs to be taken when solving the inverse problem for a non-equatorial geodesic when both endpoints are on the equator. If \(\phi _1 = \phi _2 = 0\), set \(\phi _1 = -0\) when determining \(\sigma _1\) and \(\omega _1\) using Eqs. (11) and (12) of AG. The library function atan2 will use the sign of zero to determine the correct quadrant. In addition, \(\alpha _1 = {\textstyle \frac{1}{2}}\pi \) should be treated as \(\alpha _1 = {\textstyle \frac{1}{2}}\pi +\delta \) (e.g., by setting \(\cos \alpha _1\) to some tiny negative value \(-\delta \)); this breaks the degeneracy in the equation for \(\sigma _1\).
1.4 A.4 An improved series for \(A_2\)
The series for \(A_2\), Eq. (42) in AG, converges slightly faster if we expand \({(1+\epsilon )}A_2\), instead of \(A_2/{(1-\epsilon )}\). The resulting series is
1.5 A.5 Re-expansion of the area integral
Equations (63) of AG give coefficients \(C_{4l}\) for the Fourier series for the area integral. These are Taylor series with \(e'^2\) and \(k^2\) as small parameters. The radius of convergence for this series is \(|e'| = 1\); this means that the series diverges for oblate ellipsoids with \(a > \sqrt{2}b\). This problem is remedied by expanding, instead, in terms of
the same small parameters used by Helmert for the Taylor series expansion of the longitude integral, Eq. (12). The radius of convergence of the resulting series is \(|n| = 1\) covering all eccentricities. The Fourier coefficients can then be written as
At the order shown, this series gives full double precision accuracy for the area for \(|f| \le \frac{1}{50}\).
B Comparison with Nowak et al. (2022)
Nowak and Nowak Da Costa (2022, here called NNdC), also consider the problem of geodesics on an arbitrary ellipsoid. Their starting point for evaluating the integrals for the distance and longitude is expanding \(\sqrt{1-e^2}\) as a Taylor series. So, as a preliminary matter, their methods fail to converge for \(|e^2| > 1\), i.e., for prolate ellipsoids with \(b > \sqrt{2}a\). Furthermore, their results for the integrals are unnecessarily complicated given that these can be put in closed form in terms of elliptic integrals and evaluated using Carlson (1995); see Sect. 2.
Therefore, let us concentrate on their series for computing the area. Their expression for the area, Eqs. (72), is the same as our Eqs. (18) with the substitution
where
The function \(\mathop {\textrm{Ar}}\limits (C^2, \rho ^2)\) is, in turn, given by an infinite sum, their Eq. (69). For the case considered in Tables 1 and 2, namely computing the area under a geodesic segment between its node and its vertex with \(\alpha _0=\frac{1}{4}\pi \), the two methods yield the same results provided that \(|e^2| < 1\); this serves to validate both approaches. We can therefore include enough terms in the infinite sum to limit the errors in the area to \(2^{-53}c^2\), the same criterion we used in selecting the number of points to use for the DST. Table 3 compares this number, \(N_{\textrm{NNdC}}\), to the corresponding number for the DST, \(N_{\textrm{DST}}\), from Fig. 5. We can make a few points here:
-
1.
\(N_{\textrm{NNdC}}\) is consistently greater than \(N_{\textrm{DST}}\), in some cases, by a large factor.
-
2.
The value \(N_{\textrm{DST}}\) is selected to meet the accuracy threshold for all geodesics on an ellipsoid with the given n, while, here, I determined \(N_{\textrm{NNdC}}\) only for one particular value \(\alpha _0 = \frac{1}{4}\pi \).
-
3.
The computational cost for evaluating the area integral with the method of NNdC scales as \(O(N_{\textrm{NNdC}}^2)\) which is more expensive than for the DST method, \(O(N_{\textrm{DST}}\log N_{\textrm{DST}})\).
-
4.
The results in Table 3 were found using high precision arithmetic and so reflect only the truncation errors in both methods. NNdC have not provided an implementation of their method, so it is not possible to compare either the roundoff errors or the timing; however, considering points 1 and 3, it is likely that their method is less accurate and slower than the DST method.
Rights and permissions
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article’s Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article’s Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.
About this article
Cite this article
Karney, C.F.F. Geodesics on an arbitrary ellipsoid of revolution. J Geod 98, 4 (2024). https://doi.org/10.1007/s00190-023-01813-2
Received:
Accepted:
Published:
DOI: https://doi.org/10.1007/s00190-023-01813-2