1 Introduction

The distance d between two points on two Keplerian orbits with a common focus, that we call Keplerian distance, appears in a natural way in Celestial Mechanics. The absolute minimum of d is called MOID (minimum orbital intersection distance), or simply orbit distance in the literature, and we denote it by \(d_{\textrm{min}}\). It is important to be able to track \(d_{\textrm{min}}\), and actually all the local minimum points of d, to detect possible impacts between two celestial bodies following approximately these trajectories, e.g., an asteroid with the Earth (Milani et al. 2001, 2005), or two Earth satellites (Rossi et al. 2020). Moreover, the information given by \(d_{\textrm{min}}\) is useful to understand observational biases in the distribution of the known population of NEAs, see Gronchi and Valsecchi (2013). Because of the growing number of Earth satellites (e.g., the mega constellations of satellites that are going to be launched, see Arroyo-Parejo et al. 2021) and discovered asteroids, fast and reliable methods to compute the minimum values of d are required.

The computation of the minimum points of d can be performed by searching for all the critical points of \(d^2\), where considering the squared distance allows us to include trajectory-crossing points in the results.

There are several papers in the literature concerning the computation of the critical points of \(d^2\), e.g., Sitarski (1968), Dybczynski et al. (1986), Kholshevnikov and Vassiliev (1999), Gronchi (2002), Gronchi (2005), Baluyev and Kholshevnikov (2005). Some authors also propose methods for a fast computation of \(d_{\textrm{min}}\) only, e.g., Wisniowski and Rickman (2013), Hedo et al. (2018).

We will focus on an algebraic approach for the case of two elliptic trajectories, as in Kholshevnikov and Vassiliev (1999), Gronchi (2002). In Kholshevnikov and Vassiliev (1999), the critical points of \(d^2\) are found by computing the roots of a trigonometric polynomial g(u) of degree 8, where u is the eccentric anomaly parametrizing one of the trajectories. The polynomial g(u) is obtained by the computation of a Groebner basis, implying that generically we cannot solve this problem by a polynomial with a smaller degree. In Gronchi (2002), resultant theory is applied to a system of two bivariate ordinary polynomials, together with the discrete Fourier transform, to obtain (generically) a univariate polynomial of degree 20 in a variable t, with a factor \((1+t^2)^2\) leading to 4 pure imaginary roots that are discarded, so that we may have at most 16 real roots. Note that the trigonometric polynomial g(u) of degree 8 corresponds to an ordinary polynomial of degree 16 in the variable t through the transformation \(t=\tan (u/2)\). These methods were extended to the case of unbounded conics with a common focus in Baluyev and Kholshevnikov (2005), Gronchi (2005).

In this paper, we revisit the computation of the critical points of \(d^2\) for two elliptic trajectories by applying resultant theory to polynomial systems written in terms of the eccentric or the true anomalies. We obtain different methods using either ordinary or trigonometric polynomials. Moreover, we are able to compute via resultant theory the 8-th degree trigonometric polynomial g(u) found by Kholshevnikov and Vassiliev (1999), and its analogue using the true anomalies (see Sects. 4, 5). Some numerical tests comparing these methods are presented. We also test the reliability of the methods by taking advantage of the estimates for the values of \(d_{\textrm{min}}\) introduced in Gronchi and Valsecchi (2013) when one trajectory is circular. For the case of two ellipses, since we do not have such estimates for \(d_{\textrm{min}}\), we use the optimal bounds for the nodal distance \(\delta _{\textrm{nod}}\) derived in Gronchi and Niederman (2020).

After introducing some notation in Sect. 2, we deal with the problem using eccentric anomalies and ordinary polynomials in Sect. 3. In Sects. 4 and 5, we describe other procedures employing trigonometric polynomials and, respectively, eccentric or true anomalies. Some numerical tests and the reliability of our computations are discussed in Sect. 6. Finally, we present results for the maximum number of critical points in the planar problem in Sect. 7 and draw some conclusions in Sect. 8. Additional details of the computations can be found in the Appendix.

2 Preliminaries

Let \({{\mathcal {E}}}_1\) and \({{\mathcal {E}}}_2\) be two confocal elliptic trajectories, with \({{\mathcal {E}}}_i\) defined by the five Keplerian orbital elements \(a_i,e_i,i_i,\Omega _i,\omega _i\). We introduce the Keplerian distance

$$\begin{aligned} d(V) = \sqrt{\langle {{\mathcal {X}}}_1-{{\mathcal {X}}}_2,{{\mathcal {X}}}_1-\mathcal{X}_2\rangle }, \end{aligned}$$
(1)

where \({{\mathcal {X}}}_1,{{\mathcal {X}}}_2\in \mathbb {R}^3\) are the Cartesian coordinates of a point on \({{\mathcal {E}}}_1\) and a point on \({{\mathcal {E}}}_2\), corresponding to the vector \(V=(v_1,v_2)\), where \(v_i\) is a parameter along the trajectory \({{\mathcal {E}}}_i\). In this paper we will parametrize the orbits either with the eccentric anomalies \(u_i\) or with the true anomalies \(f_i\).

Let \((x_1,y_1)\) and \((x_2,y_2)\) be Cartesian coordinates of two points on the two trajectories, each in its respective plane. The origin for both coordinate systems is the common focus of the two ellipses. We can write

$$\begin{aligned} {{\mathcal {X}}}_1&= x_1\,{{\mathcal {P}}} + y_1\,{{\mathcal {Q}}},\\ {{\mathcal {X}}}_2&= x_2\,{{\mathfrak {p}}} + y_2\,{{\mathfrak {q}}}, \end{aligned}$$

with

$$\begin{aligned} {{\mathcal {P}}}&= \left( P_x\,,P_y\,,P_z\right) ,&{{\mathcal {Q}}}&= \left( Q_x\,,Q_y\,,Q_z\right) ,\\ {{\mathfrak {p}}}&= \left( p_x\,,p_y\,,p_z\right) ,&{{\mathfrak {q}}}&= \left( q_x\,,q_y\,,q_z\right) , \end{aligned}$$

where

$$\begin{aligned}{} & {} P_x = \cos \omega _1\cos \Omega _1 - \cos i_1\sin \omega _1\sin \Omega _1,\\{} & {} P_y = \cos \omega _1\sin \Omega _1 + \cos i_1\sin \omega _1\cos \Omega _1,\\{} & {} P_z =\sin \omega _1\sin i_1, \\{} & {} Q_x = -\sin \omega _1\cos \Omega _1 - \cos i_1\cos \omega _1\sin \Omega _1,\\{} & {} Q_y = -\sin \omega _1\sin \Omega _1 + \cos i_1\cos \omega _1\cos \Omega _1,\\{} & {} Q_z =\cos \omega _1 \sin i_1, \\{} & {} p_x = \cos \omega _2 \cos \Omega _2 - \cos i_2\sin \omega _2\sin \Omega _2, \\{} & {} p_y = \cos \omega _2 \sin \Omega _2 + \cos i_2\sin \omega _2\cos \Omega _2, \\{} & {} p_z = \sin \omega _2 \sin i_2, \\{} & {} q_x = -\sin \omega _2 \cos \Omega _2 - \cos i_2\cos \omega _2\sin \Omega _2, \\{} & {} q_y = -\sin \omega _2 \sin \Omega _2 + \cos i_2\cos \omega _2\cos \Omega _2, \\{} & {} q_z = \cos \omega _2 \sin i_2. \end{aligned}$$

If we use the eccentric anomalies \(u_i\), we have

$$\begin{aligned} x_i = a_i(\cos u_i - e_i), \quad y_i = a_i\sqrt{1-e_i^2}\sin u_i, \end{aligned}$$

for \(i=1,2\), while with the true anomalies \(f_i\) we have

$$\begin{aligned} x_i = r_i\cos f_i,\quad y_i = r_i\sin f_i,\qquad r_i = \frac{a_i \left( 1-e_i^2 \right) }{1+e_i\cos f_i}. \end{aligned}$$

Note that

$$\begin{aligned} |\mathcal {P}| = |\mathcal {Q}| = |\mathfrak {p}| = |\mathfrak {q}| = 1, \qquad \langle \mathcal {P},\mathcal {Q}\rangle = \langle \mathfrak {p},\mathfrak {q}\rangle = 0, \end{aligned}$$

and set

$$\begin{aligned} K = \langle {{\mathcal {P}}},{{\mathfrak {p}}}\rangle , \hspace{14.22636pt}L = \langle {{\mathcal {Q}}},{{\mathfrak {p}}}\rangle , \hspace{14.22636pt}M = \langle {{\mathcal {P}}},{{\mathfrak {q}}}\rangle , \hspace{14.22636pt}N = \langle {{\mathcal {Q}}},{{\mathfrak {q}}}\rangle . \end{aligned}$$

3 Eccentric anomalies and ordinary polynomials

We look for the critical points of the squared distance \(d^2\) as a function of the eccentric anomalies \(u_1, u_2\), that is we consider the system

$$\begin{aligned} \nabla d^2(u_1,u_2) = \textbf{0}, \end{aligned}$$
(2)

where \(\nabla d^2 = \bigl (\frac{\partial d^2}{\partial u_1}, \frac{\partial d^2}{\partial u_2}\bigr )\). We can write

$$\begin{aligned} \left\{ \begin{aligned}&\frac{1}{2}\frac{\partial d^2}{\partial u_1} = \left\langle \frac{\partial {{\mathcal {X}}}_1}{\partial u_1},{{\mathcal {X}}}_1-{{\mathcal {X}}}_2 \right\rangle = \frac{\partial x_1}{\partial u_1}(x_1 - Kx_2 - My_2) + \frac{\partial y_1}{\partial u_1}(y_1 - Lx_2 - Ny_2),\\&\frac{1}{2}\frac{\partial d^2}{\partial u_2} = - \left\langle \frac{\partial {{\mathcal {X}}}_2}{\partial u_2},{{\mathcal {X}}}_1-{{\mathcal {X}}}_2 \right\rangle = \frac{\partial x_2}{\partial u_2}(x_2 - Kx_1 - Ly_1) + \frac{\partial y_2}{\partial u_2}(y_2 - Mx_1 - Ny_1), \end{aligned} \right. \end{aligned}$$
(3)

where

$$\begin{aligned} \frac{\partial x_i}{\partial u_i} = -a_i\sin u_i,\qquad \frac{\partial y_i}{\partial u_i} = a_i\sqrt{1-e_i^2}\cos u_i,\hspace{28.45274pt}i=1,2. \end{aligned}$$

System (3) can be written as

$$\begin{aligned} \left\{ \begin{aligned}&2(A_1 - A_3)\sin u_1\cos u_1 + A_7\cos u_1\sin u_2 + A_8\cos u_1\cos u_2 \\&\quad - A_9\sin u_1\sin u_2 - A_{10}\sin u_1\cos u_2 + A_{11}\cos u_1 - A_{12}\sin u_1 = 0, \\&2(A_4 - A_6)\sin u_2\cos u_2 + A_7\sin u_1 \cos u_2 - A_8\sin u_1\sin u_2 \\&\quad + A_9\cos u_1\cos u_2 - A_{10}\cos u_1\sin u_2 + A_{13}\cos u_2 - A_{14}\sin u_2 = 0, \end{aligned} \right. \end{aligned}$$
(4)

with

$$\begin{aligned} \begin{aligned}&A_1 = a_1^2(1-e_1^2),&\quad&A_2 = 0,\\&A_3 = a_1^2,&\quad&A_4 = a_2^2 \left( 1-e_2^2 \right) ,\\&A_5 = 0,&\quad&A_6 = a_2^2, \\&A_7 = -2a_1a_2\sqrt{1-e_1^2}\sqrt{1-e_2^2} N,&\quad&A_8 = -2a_1a_2\sqrt{1-e_1^2} L, \\&A_9 = -2a_1a_2\sqrt{1-e_2^2} M,&\quad&A_{10} = -2a_1a_2 K, \\&A_{11} = 2a_1a_2e_2\sqrt{1-e_1^2} L,&\quad&A_{12} = 2a_1(a_2e_2 K - a_1e_1),\\&A_{13} = 2a_1a_2e_1\sqrt{1-e_2^2} M,&\quad&A_{14} = 2a_2(a_1e_1 K - a_2e_2). \end{aligned} \end{aligned}$$

Following (Gronchi 2002), we can transform (4) into a system of two bivariate ordinary polynomials in the variables ts through

$$\begin{aligned} \sin u_1 = \displaystyle {2t\over 1+t^2}, \qquad \cos u_1 = \displaystyle {1-t^2 \over 1+t^2}, \qquad \sin u_2 = \displaystyle {2s\over 1+s^2}, \qquad \cos u_2 = \displaystyle {1-s^2 \over 1+s^2}. \end{aligned}$$

Then, (4) becomes

$$\begin{aligned} \left\{ \begin{aligned}&p(t,s) = \alpha (t) s^2 + \beta (t) s + \gamma (t) = 0,\\&q(t,s) = A (t) s^4 + B (t) s^3 + D (t) s - A (t) = 0, \end{aligned} \right. \end{aligned}$$
(5)

where

$$\begin{aligned} \alpha (t)&= (A_{11}-A_8) + (4A_1 -4A_3 + 2A_{10} -2A_{12})t \\&\,\quad +(-4A_1 +4A_3 +2A_{10} -2A_{12})t^3 +(A_8-A_{11})t^4, \\ \beta (t)&= 2A_7 -4A_9t -4A_9t^3 -2A_7t^4, \\ \gamma (t)&= (A_{11}+A_8) + (4A_1 -4A_3 - 2A_{10} -2A_{12})t \\&\,\quad +(-4A_1 +4A_3 -2A_{10} -2A_{12})t^3-(A_8+A_{11})t^4 \end{aligned}$$

and

$$\begin{aligned} A(t)&= -(A_9+A_{13}) -2A_7t +(A_9-A_{13})t^2, \\ B(t)&= (-4A_4 + 4A_6 - 2A_{10} - 2A_{14}) - 4A_8t \\&\,\quad +(-4A_4+4A_6+ 2A_{10} - 2A_{14})t^2, \\ D(t)&= (4A_4 - 4A_6 - 2A_{10} - 2A_{14}) - 4A_8t \\&\,\quad +(4A_4 - 4A_6 + 2A_{10} - 2A_{14})t^2. \end{aligned}$$

Let

$$\begin{aligned} S_0 = \left( \begin{array}{ccccrr} \alpha &{}\quad 0 &{}\quad 0 &{}\quad 0 &{}\quad A &{}\quad 0 \\ \beta &{}\quad \alpha &{}\quad 0 &{}\quad 0 &{}\quad B &{}\quad A \\ \gamma &{}\quad \beta &{}\quad \alpha &{}\quad 0 &{}\quad 0 &{}\quad B \\ 0 &{}\quad \gamma &{}\quad \beta &{}\quad \alpha &{}\quad D &{}\quad 0 \\ 0 &{}\quad 0 &{}\quad \gamma &{}\quad \beta &{}\quad -A &{}\quad D \\ 0 &{}\quad 0 &{}\quad 0 &{}\quad \gamma &{}\quad 0 &{}\quad -A \end{array} \right) \end{aligned}$$
(6)

be the Sylvester matrix related to (5). From resultant theory (Cox et al. 1992) we know that the complex roots of \(\det (S_0(t))\) correspond to all the t-components of the solutions \((t, s)\in \mathbb {C}^2\) of (5). The determinant \(\det (S_0(t))\) is in general a polynomial of degree 20 in t. We notice that it can be factorized as

$$\begin{aligned} \det \bigl (S_0(t)\bigr )=(1+t^2)^2\det \bigl (\hat{S}(t)\bigr ), \end{aligned}$$

with

$$\begin{aligned} \hat{S} = \left( \begin{array}{cccccc} \widetilde{\sigma }_1 &{}\quad -\widetilde{\sigma }_2 &{}\quad -\widetilde{\sigma }_1 &{}\quad \widetilde{\sigma }_2 &{}\quad 0 &{}\quad -\widetilde{\sigma }_3 \\ \widetilde{\sigma }_2 &{}\quad \widetilde{\sigma }_1 &{}\quad -\widetilde{\sigma }_2 &{}\quad -\widetilde{\sigma }_1 &{}\quad \widetilde{\sigma }_3 &{}\quad 0 \\ \sigma _4 &{}\quad \sigma _2 &{}\quad \sigma _1 &{}\quad -\sigma _2 &{}\quad \sigma _6 &{}\quad \sigma _3 \\ 0 &{}\quad \sigma _4 &{}\quad \sigma _2 &{}\quad \sigma _1 &{}\quad \sigma _5 &{}\quad \sigma _6 \\ 0 &{}\quad 0 &{}\quad \sigma _4 &{}\quad \sigma _2 &{}\quad -\sigma _6 &{}\quad \sigma _5 \\ 0 &{}\quad 0 &{}\quad 0 &{}\quad \sigma _4 &{}\quad 0 &{}\quad -\sigma _6 \end{array} \right) , \end{aligned}$$
(7)

where

$$\begin{aligned} \begin{aligned}&\sigma _1 = \alpha -\gamma ,\quad&\sigma _2&= \beta ,\quad&\sigma _3&= B-D, \\&\widetilde{\sigma }_1 = \frac{\alpha -\gamma }{1+t^2},\quad&\widetilde{\sigma }_2&= \frac{\beta }{1+t^2},\quad&\widetilde{\sigma }_3&= \frac{B-D}{1+t^2}, \\&\sigma _4 = \gamma ,\quad&\sigma _5&= D, \quad&\sigma _6&= A. \\ \end{aligned} \end{aligned}$$
(8)

Therefore, to find the t-components corresponding to the critical points, we can look for the solutions of \(\det ({\hat{S}})=0\), which in general is a polynomial equation of degree 16. We can follow the same steps explained in Gronchi (2005, Sect. 4.3) to obtain the coefficients of the polynomial \(\det ({\hat{S}})\) by an evaluation/interpolation procedure based on the discrete Fourier transform. Then, the method described in Bini (1997) is applied to compute its roots. We substitute each of the real roots t of \(\det ({\hat{S}})\) in (5) and use the first equation \(p(t,s)=0\) to compute the two possible values of the s variable. Finally, we evaluate q at these points (ts) and choose the value of s that gives the evaluation with the smallest absolute value.

3.1 Angular shifts

To improve the numerical stability of the method we introduce angular shifts. Define a shifted angle \({v_1 = u_1-s_1}\), for some \(s_1\in [0,2\pi )\), and let

$$\begin{aligned} \sin v_1 = \frac{2z}{1+z^2},\qquad \cos v_1 = \frac{1-z^2}{1+z^2}. \end{aligned}$$
(9)

Then, system (4) becomes

$$\begin{aligned} \left\{ \begin{aligned}&{\tilde{p}}(z,s) = {\tilde{\alpha }} (z) s^2 + {\tilde{\beta }} (z) s + {\tilde{\gamma }} (z) = 0,\\&{\tilde{q}}(z,s) = {\tilde{A}} (z) s^4 + {\tilde{B}} (z) s^3 + {\tilde{D}} (z) s - {\tilde{A}} (z) = 0. \end{aligned} \right. \end{aligned}$$
(10)

The coefficients \({\tilde{\alpha }}, {\tilde{\beta }}, {\tilde{\gamma }}, {\tilde{A}}, {\tilde{B}}, {\tilde{D}}\) are written in Appendix A. If \(T_0(z)\) is the Sylvester matrix related to (10) we get

$$\begin{aligned} \det (T_0(z)) = (1+z^2)^2\det ({\hat{T}}(z)), \end{aligned}$$

with

$$\begin{aligned} \hat{T} = \left( \begin{array}{cccccc} \widetilde{\tau }_1 &{}\quad -\widetilde{\tau }_2 &{}\quad -\widetilde{\tau }_1 &{}\quad \widetilde{\tau }_2 &{}\quad 0 &{}\quad -\widetilde{\tau }_3 \\ \widetilde{\tau }_2 &{}\quad \widetilde{\tau }_1 &{}\quad -\widetilde{\tau }_2 &{}\quad -\widetilde{\tau }_1 &{}\quad \widetilde{\tau }_3 &{}\quad 0 \\ \tau _4 &{}\quad \tau _2 &{}\quad \tau _1 &{}\quad -\tau _2 &{}\quad \tau _6 &{}\quad \tau _3 \\ 0 &{}\quad \tau _4 &{}\quad \tau _2 &{}\quad \tau _1 &{}\quad \tau _5 &{}\quad \tau _6 \\ 0 &{}\quad 0 &{}\quad \tau _4 &{}\quad \tau _2 &{}\quad -\tau _6 &{}\quad \tau _5 \\ 0 &{}\quad 0 &{}\quad 0 &{}\quad \tau _4 &{}\quad 0 &{}\quad -\tau _6 \end{array} \right) , \end{aligned}$$

where

$$\begin{aligned} \begin{aligned}&\tau _1 = {\tilde{\alpha }}-{\tilde{\gamma }},\quad&\tau _2&= {\tilde{\beta }},\quad&\tau _3&= {\tilde{B}}-{\tilde{D}}, \\&\widetilde{\tau }_1 = \frac{{\tilde{\alpha }}-{\tilde{\gamma }}}{1+z^2},\quad&\widetilde{\tau }_2&= \frac{{\tilde{\beta }}}{1+z^2},\quad&\widetilde{\tau }_3&= \frac{{\tilde{B}}-{\tilde{D}}}{1+z^2}, \\&\tau _4 = {\tilde{\gamma }},\quad&\tau _5&= {\tilde{D}}, \quad&\tau _6&= {\tilde{A}}. \\ \end{aligned} \end{aligned}$$
(11)

We find the values of z by solving the polynomial equation \(\det ({\hat{T}})=0\), which again has generically degree 16. We compute the values of \(v_1\) from (9) and shift back to obtain the \(u_1\) components of the critical points. Substituting in (4) and applying the angular shift \(u_2=v_2+s_2\), we consider the system

$$\begin{aligned} \left\{ \begin{aligned}&\textsf{A}\cos v_2 + \textsf{B}\sin v_2 + \textsf{C} = 0,\\&\cos ^2v_2 + \sin ^2v_2 -1 = 0, \end{aligned} \right. \end{aligned}$$

where the first equation corresponds to the first equation in (4), and

$$\begin{aligned} \begin{aligned}&\textsf{A} = (A_8\cos u_1-A_{10}\sin u_1)\cos s_2 + (A_7\cos u_1-A_9\sin u_1)\sin s_2,\\&\textsf{B} = -(A_8\cos u_1-A_{10}\sin u_1)\sin s_2 + (A_7\cos u_1-A_9\sin u_1)\cos s_2,\\&\textsf{C} = 2(A_1-A_3)\sin u_1\cos u_1+A_{11}\cos u_1-A_{12}\sin u_1. \end{aligned} \end{aligned}$$

For each value of \(u_1\), we compute two solutions for \(\cos v_2\), \(\sin v_2\) and the corresponding values of \(\cos u_2\), \(\sin u_2\). We choose between them by substituting in the second equation in (4).

4 Eccentric anomalies and trigonometric polynomials

To work with trigonometric polynomials, we write system (3) as

$$\begin{aligned} \left\{ \begin{aligned}&\lambda \sin u_1\cos u_1 + \mu \cos u_1 + \nu \sin u_1 = 0, \\&\alpha \cos u_1 + \beta \sin u_1 + \gamma = 0, \\ \end{aligned} \right. \end{aligned}$$
(12)

where

$$\begin{aligned} \begin{aligned} \lambda&= a_1e_1^2, \\ \mu&= a_2\sqrt{1-e_1^2}\Bigl (\sqrt{1-e_2^2} N \sin u_2 + L \cos u_2 - e_2 L \Bigr ), \\ \nu&= a_2e_2K - a_1e_1 -a_2\sqrt{1-e_2^2}M\sin u_2 - a_2K\cos u_2, \\ \alpha&= a_1\Bigl (\sqrt{1-e_2^2} M \cos u_2 - K \sin u_2\Bigr ), \\ \beta&= a_1\sqrt{1-e_1^2}\Bigl (\sqrt{1-e_2^2} N \cos u_2 - L \sin u_2\Bigr ), \\ \gamma&= a_2e_2^2\sin u_2\cos u_2 - a_1e_1\sqrt{1-e_2^2} M \cos u_2 +(a_1e_1 K - a_2e_2)\sin u_2. \\ \end{aligned} \end{aligned}$$

Inserting relation

$$\begin{aligned} \sin u_1 = -\frac{1}{\beta }(\alpha \cos u_1 + \gamma ) \end{aligned}$$
(13)

into \(\cos ^2u_1+\sin ^2u_1-1 = 0\) and into the first equation in (12), we obtain

$$\begin{aligned} \left\{ \begin{aligned}&(\alpha ^2+\beta ^2)\cos ^2 u_1 + 2\alpha \gamma \cos u_1 + \gamma ^2-\beta ^2 = 0, \\&- \alpha \lambda \cos ^2 u_1 + (\beta \mu - \lambda \gamma -\alpha \nu )\cos u_1 -\gamma \nu = 0. \\ \end{aligned} \right. \end{aligned}$$
(14)

We call \(p_1\), \(p_2\) the two trigonometric polynomials appearing on the left-hand side of (14). The Sylvester matrix of \(p_1\) and \(p_2\) is

$$\begin{aligned} \mathscr {S} = \left[ \begin{array}{cccc} \alpha ^2+\beta ^2 &{}\quad 0 &{}\quad - \alpha \lambda &{}\quad 0 \\ 2\alpha \gamma &{}\quad \alpha ^2+\beta ^2 &{}\quad \beta \mu - \lambda \gamma -\alpha \nu &{}\quad - \alpha \lambda \\ \gamma ^2-\beta ^2 &{}\quad 2\alpha \gamma &{}\quad -\gamma \nu &{}\quad \beta \mu - \lambda \gamma -\alpha \nu \\ 0 &{}\quad \gamma ^2-\beta ^2 &{}\quad 0 &{}\quad -\gamma \nu \\ \end{array} \right] . \end{aligned}$$

We define

$$\begin{aligned} \mathscr {G}(u_2) = \det \mathscr {S}(u_2), \end{aligned}$$

which corresponds to the resultant of \(p_1\), \(p_2\) with respect to \(\cos u_1\) and is a trigonometric polynomial in \(u_2\) only. The \(u_2\) component of each critical point satisfies \(\mathscr {G}(u_2)=0\).

Proposition 1

We can extract a factor \(\beta ^2\) from \(\det \mathscr {S}\).

Proof

Using simple properties of determinants, we can write \(\det \mathscr {S}\) as a sum of different terms. The terms independent from \(\beta \) in this sum are given by

$$\begin{aligned}{} & {} \left| \begin{array}{cccc} \alpha ^2 &{}\quad 0 &{}\quad - \alpha \lambda &{}\quad 0 \\ 2\alpha \gamma &{}\quad \alpha ^2 &{}\quad - \lambda \gamma -\alpha \nu &{}\quad - \alpha \lambda \\ \gamma ^2 &{}\quad 2\alpha \gamma &{}\quad -\gamma \nu &{}\quad - \lambda \gamma -\alpha \nu \\ 0 &{}\quad \gamma ^2 &{}\quad 0 &{}\quad -\gamma \nu \\ \end{array} \right| \\{} & {} \quad ={\left| \begin{array}{cccc} \alpha ^2 &{}\quad v0 &{}\quad \alpha \lambda &{}\quad 0 \\ \alpha \gamma &{}\quad 0 &{}\quad \lambda \gamma &{}\quad 0 \\ \gamma ^2 &{}\quad 2\alpha \gamma &{}\quad \gamma \nu &{}\quad \lambda \gamma +\alpha \nu \\ 0 &{}\quad \gamma ^2 &{}\quad 0 &{}\quad \gamma \nu \\ \end{array} \right| } +\left| \begin{array}{cccc} \alpha ^2 &{}\quad 0 &{}\quad \alpha \lambda &{}\quad 0 \\ \alpha \gamma &{}\quad \alpha ^2 &{}\quad \alpha \nu &{}\quad \alpha \lambda \\ \gamma ^2 &{}\quad 2\alpha \gamma &{}\quad \gamma \nu &{}\quad \lambda \gamma +\alpha \nu \\ 0 &{}\quad \gamma ^2 &{}\quad 0 &{}\quad \gamma \nu \\ \end{array} \right| \\{} & {} \quad = \left| \begin{array}{cccc} \alpha ^2 &{}\quad 0 &{}\quad \alpha \lambda &{}\quad 0 \\ \alpha \gamma &{}\quad \alpha ^2 &{}\quad \alpha \nu &{}\quad \alpha \lambda \\ 0 &{}\quad \alpha \gamma &{}\quad 0 &{}\quad \alpha \nu \\ 0 &{}\quad \gamma ^2 &{}\quad 0 &{}\quad \gamma \nu \\ \end{array} \right| + \left| \begin{array}{cccc} \alpha ^2 &{}\quad 0 &{}\quad \alpha \lambda &{}\quad 0 \\ \alpha \gamma &{}\quad \alpha ^2 &{}\quad \alpha \nu &{}\quad \alpha \lambda \\ \gamma ^2 &{}\quad \gamma \alpha &{}\quad \gamma \nu &{}\quad \gamma \lambda \\ 0 &{}\quad \gamma ^2 &{}\quad 0 &{}\quad \gamma \nu \\ \end{array} \right| , \\ \end{aligned}$$

and both determinants are 0. The linear terms in \(\beta \) are given by

$$\begin{aligned} \left| \begin{array}{cccc} \alpha ^2 &{}\quad 0 &{}\quad - \alpha \lambda &{}\quad 0 \\ 2\alpha \gamma &{}\quad \alpha ^2 &{}\quad - \lambda \gamma -\alpha \nu &{}\quad 0 \\ \gamma ^2 &{}\quad 2\alpha \gamma &{}\quad -\gamma \nu &{}\quad \beta \mu \\ 0 &{}\quad \gamma ^2 &{}\quad 0 &{}\quad 0 \\ \end{array} \right| + \left| \begin{array}{cccc} \alpha ^2 &{}\quad 0 &{}\quad 0 &{}\quad 0 \\ 2\alpha \gamma &{}\quad \alpha ^2 &{}\quad \beta \mu &{}\quad - \alpha \lambda \\ \gamma ^2 &{}\quad 2\alpha \gamma &{}\quad 0 &{}\quad -\lambda \gamma -\alpha \nu \\ 0 &{}\quad \gamma ^2 &{}\quad 0 &{}\quad -\gamma \nu \\ \end{array} \right| , \end{aligned}$$

and this sum is 0, because the two determinants are opposite. Therefore, \(\mathscr {G}(u_2)\) is made by terms of order higher than 1 in \(\beta \). It results

$$\begin{aligned} \mathscr {G}(u_2) = \mathfrak {D}_1 + \mathfrak {D}_2 + \mathfrak {D}_3, \end{aligned}$$

where

$$\begin{aligned}{} & {} \mathfrak {D}_1 = \left| \begin{array}{cccc} \beta ^2 &{}\quad 0 &{}\quad - \alpha \lambda &{}\quad 0 \\ 0 &{}\quad \beta ^2 &{}\quad \beta \mu - \lambda \gamma -\alpha \nu &{}\quad - \alpha \lambda \\ -\beta ^2 &{}\quad 0 &{}\quad -\gamma \nu &{}\quad \beta \mu - \lambda \gamma -\alpha \nu \\ 0 &{}\quad -\beta ^2 &{}\quad 0 &{}\quad -\gamma \nu \\ \end{array} \right| , \\{} & {} \mathfrak {D}_2 = \left| \begin{array}{cccc} \beta ^2 &{}\quad 0 &{}\quad - \alpha \lambda &{}\quad 0 \\ 0 &{}\quad \alpha ^2 &{}\quad \beta \mu - \lambda \gamma -\alpha \nu &{}\quad - \alpha \lambda \\ -\beta ^2 &{}\quad 2\alpha \gamma &{}\quad -\gamma \nu &{}\quad \beta \mu - \lambda \gamma -\alpha \nu \\ 0 &{}\quad \gamma ^2 &{}\quad 0 &{}\quad -\gamma \nu \\ \end{array} \right| \\ {}{} & {} \quad \quad \quad +\left| \begin{array}{cccc} \alpha ^2 &{}\quad 0 &{}\quad - \alpha \lambda &{}\quad 0 \\ 2\alpha \gamma &{}\quad \beta ^2 &{}\quad \beta \mu - \lambda \gamma -\alpha \nu &{}\quad - \alpha \lambda \\ \gamma ^2 &{}\quad 0 &{}\quad -\gamma \nu &{}\quad \beta \mu - \lambda \gamma -\alpha \nu \\ 0 &{}\quad -\beta ^2 &{}\quad 0 &{}\quad -\gamma \nu \\ \end{array} \right| , \\{} & {} \mathfrak {D}_3 = \left| \begin{array}{cccc} \alpha ^2 &{}\quad 0 &{}\quad 0 &{}\quad 0 \\ 2\alpha \gamma &{}\quad \alpha ^2 &{}\quad \beta \mu &{}\quad 0 \\ \gamma ^2 &{}\quad 2\alpha \gamma &{}\quad 0 &{}\quad \beta \mu \\ 0 &{}\quad \gamma ^2 &{}\quad 0 &{}\quad 0 \\ \end{array} \right| . \\ \end{aligned}$$

Their explicit expressions read

$$\begin{aligned}{} & {} \mathfrak {D}_1 =\beta ^4\bigl [(\alpha \lambda +\gamma \nu )^2 - (\beta \mu -\lambda \gamma -\alpha \nu )^2\bigr ], \\{} & {} \mathfrak {D}_2 =\beta ^2\left[ 2\alpha \beta \gamma \mu (\gamma \nu -\alpha \lambda ) +((\beta \mu -\lambda \gamma -\alpha \nu )^2-4\alpha \gamma \lambda \nu )(\gamma ^2-\alpha ^2)\right] , \\{} & {} \mathfrak {D}_3 = \alpha ^2\beta ^2\gamma ^2\mu ^2. \end{aligned}$$

\(\square \)

The trigonometric polynomial

$$\begin{aligned} g(u_2)&= \mathscr {G}(u_2)/\beta ^2\\&={\gamma }^{4}{\lambda }^{2}-{\beta }^{4}{\mu }^{2}-{\alpha }^{4}{\nu }^{2} +2\,\mu \,\lambda \,\gamma \,\beta \, \left( {\beta }^{2}-{\gamma }^{2} \right) +2\,\mu \,\nu \,\alpha \,\beta \, \left( {\alpha }^{2}+{\beta }^{2}\right) \\&\,\quad +2\,\lambda \,\nu \,\gamma \,\alpha \, \left( {\alpha }^{2}-{ \gamma }^{2} \right) + \left( -{\lambda }^{2}+{\mu }^{2}+{\nu }^{2} \right) \left( -{\alpha }^{2}{\beta }^{2}+{\gamma }^{2}{\alpha }^{2}+{ \gamma }^{2}{\beta }^{2} \right) \end{aligned}$$

has total degree 8 in the variables \(\cos u_2\), \(\sin u_2\), and corresponds to the polynomial g introduced in Kholshevnikov and Vassiliev (1999) with Groebner bases theory. For this reason, generically, there is no polynomial of smaller degree giving all the \(u_2\) components of the critical points of \(d^2\).

We now explain the procedure to reduce the problem to the computation of the roots of a univariate polynomial. Set

$$\begin{aligned} \mathfrak {g}(x,y) = g(u_2), \end{aligned}$$

where

$$\begin{aligned} x=\cos u_2, \qquad y = \sin u_2. \end{aligned}$$

We find that

$$\begin{aligned} \mathfrak {g}(x,y) = \sum _{j=0}^6 g_j(x) y^j \end{aligned}$$

for some polynomial coefficients \(g_j\) such that

$$\begin{aligned} \begin{aligned}&\deg g_0 =\deg g_1 = \deg g_2 = 6,\\&\deg g_3 = 5, \quad \deg g_4 = 4, \quad \deg g_5 = 3, \quad \deg g_6 = 2. \end{aligned} \end{aligned}$$

Then, we consider the polynomial system

$$\begin{aligned} \left\{ \begin{aligned}&\mathfrak {g}(x,y) = 0, \\&x^2+y^2 -1 = 0 . \\ \end{aligned} \right. \end{aligned}$$
(15)

Using relations

$$\begin{aligned} y^{2k} = \big (1-x^2 \big )^k,\quad y^{2k+1} = y\big (1-x^2 \big )^k,\quad k\in \mathbb {N}, \end{aligned}$$

obtained from the second equation in (15), we can substitute \(\mathfrak {g}\) in system (15) with

$$\begin{aligned} \tilde{\mathfrak {g}}(x,y) = a(x)y + b(x), \end{aligned}$$

where

$$\begin{aligned} \begin{aligned} a(x)&= g_1(x) + \big (1-x^2\big )g_3(x) + \big (1-x^2\big )^2g_5(x), \\ b(x)&= g_0(x) + \big (1-x^2\big )g_2(x) + \big (1-x^2\big )^2g_4(x) + \big (1-x^2\big )^3g_6(x). \\ \end{aligned} \end{aligned}$$

We can also write

$$\begin{aligned} \begin{aligned} a(x)&= a_0(x) + x^2 a_2(x) + x^4 a_4(x), \\ b(x)&= b_0(x) + x^2b_2(x) + x^4b_4(x) + x^6b_6(x), \\ \end{aligned} \end{aligned}$$

with

$$\begin{aligned} \begin{aligned}&a_0=g_1+g_3+g_5,&a_2&=-g_3-2g_5,&a_4&=g_5,{} & {} \\&b_0=g_0+g_2+g_4+g_6,&b_2&=-g_2-2g_4-3g_6,&b_4&=g_4+3g_6,&b_6&=-g_6. \\ \end{aligned} \end{aligned}$$

Note that a and b have degree 7 and 8, respectively. We eliminate y from system

$$\begin{aligned} \left\{ \begin{aligned}&\tilde{\mathfrak {g}}(x,y) = 0, \\&x^2+y^2 -1 = 0 \\ \end{aligned} \right. \end{aligned}$$

by computing the resultant \(\mathfrak {u}(x)\) of the two polynomials with respect to y, and obtain

$$\begin{aligned} \mathfrak {u}(x)= \left| \begin{array}{ccc} a(x) &{}\quad 0 &{}\quad 1 \\ b(x) &{}\quad a(x) &{}\quad 0 \\ 0 &{}\quad b(x) &{}\quad x^2-1 \\ \end{array} \right| = a^2(x)\big (x^2-1 \big ) + b^2(x), \end{aligned}$$
(16)

which is a univariate polynomial of degree 16.

Each of the real roots x of \(\mathfrak {u}\), with \(|x|\le 1\), is substituted into the equation \(\tilde{\mathfrak {g}}(x,y) = 0\) to get the value of y. Finally, we evaluate \(\alpha ,\beta ,\gamma ,\mu ,\nu \) at the computed pairs (xy) and solve system (12) by computing the values of \(\cos u_1\) and \(\sin u_1\) from (14) and (13), respectively.

4.1 Finding the roots of \(\mathfrak {u}\) with Chebyshev’s polynomials

To compute the roots of the polynomial \(\mathfrak {u}(x)\) in a numerically stable way, we need to express \(\mathfrak {u}\) in a basis ensuring that the roots are well-conditioned functions of its coefficients. This can be achieved using Chebyshev’s polynomials (Noferini and Pérez 2017) in place of the standard monomial basis.

In the monomial basis, we have

$$\begin{aligned} \mathfrak {u}(x) = \sum _{j=0}^np_j x^j, \end{aligned}$$
(17)

for some coefficients \(p_j\). The same polynomial can be written as

$$\begin{aligned} \mathfrak {u}(x) = \sum _{j=0}^nc_j T_j(x), \end{aligned}$$
(18)

where \(T_j\) are Chebyshev’s polynomials, recursively defined by

$$\begin{aligned} T_0(x) = 1, \qquad T_1(x) = x, \qquad T_{j+1} = 2xT_j - T_{j-1}, \ j=1,\ldots ,n-1, \end{aligned}$$
(19)

which are a basis for the vector space of polynomials of degree at most n. The coefficients \(c_j\) are obtained from the \(p_j\) as follows. Setting

$$\begin{aligned} X = \left( 1, x, x^2,\ldots , x^n \right) ^t, \quad Y = \left( T_0(x), T_1(x),\ldots , T_n(x) \right) ^t \end{aligned}$$

we have

$$\begin{aligned} {A}X = Y, \end{aligned}$$
(20)

with

$$\begin{aligned} A = \left[ \begin{array}{cccc} a_{00} &{}\quad 0 &{}\quad \ldots &{}\quad 0 \\ a_{10} &{}\quad a_{11} &{}\quad \ddots &{}\quad \vdots \\ \vdots &{}\quad &{}\quad \ddots &{}\quad 0 \\ a_{n0} &{}\quad a_{n1} &{}\quad \ldots &{}\quad a_{nn} \\ \end{array} \right] , \end{aligned}$$

where the integer coefficients \(a_{ij}\) are determined from relations (19). We invert A by the following procedure. Define

$$\begin{aligned} \tilde{A} = \left[ \begin{array}{cccc} 1 &{}\quad 0 &{}\quad \ldots &{}\quad 0 \\ \frac{a_{10}}{a_{11}} &{}\quad 1 &{}\quad \ddots &{}\quad \vdots \\ \vdots &{}\quad &{}\quad \ddots &{}\quad 0 \\ \frac{a_{n0}}{a_{nn}} &{}\quad \frac{a_{n1}}{a_{nn}} &{}\quad \ldots &{}\quad 1 \\ \end{array} \right] , \qquad \tilde{Y} = \left( \frac{T_0}{a_{00}}, \frac{T_1}{a_{11}},\ldots , \frac{T_n}{a_{nn}}\right) ^t. \end{aligned}$$

Equation (20) becomes

$$\begin{aligned} \tilde{A}X = \tilde{Y}, \end{aligned}$$

with

$$\begin{aligned} \tilde{A} = I + N, \end{aligned}$$

where \(N^n=0\), that is N is a nilpotent matrix of order n. Relation

$$\begin{aligned} (I+N)\big (I-N+N^2-N^3+\cdots +(-1)^{n-1}N^{n-1}\big ) = I \end{aligned}$$

implies that the inverse of \(\tilde{A}\) is

$$\begin{aligned} \tilde{A}^{-1} = I + \sum _{j=1}^{n-1}(-1)^jN^j. \end{aligned}$$
(21)

Let us introduce the vectors

$$\begin{aligned} P = (p_0, p_1, \ldots , p_n)^t, \qquad C = (c_0,c_1,\ldots ,c_n)^t \end{aligned}$$

made by the coefficients of the polynomials in (17), (18), and the diagonal matrix

$$\begin{aligned} D = \textrm{diag}\big \{ a_{00}^{-1}, a_{11}^{-1},\ldots , a_{nn}^{-1} \big \}. \end{aligned}$$

From (20) and (21) we can write

$$\begin{aligned} X = \tilde{A}^{-1}DY, \end{aligned}$$

so that

$$\begin{aligned} \mathfrak {u}(x) = C^tY = P^tX = \big (P^t\tilde{A}^{-1}D \big )Y. \end{aligned}$$

Therefore, the relation between the coefficients \(c_j\) and \(p_j\) is given by

$$\begin{aligned} C = \big (D\tilde{A}^{-t} \big ) P. \end{aligned}$$

Searching for the roots of \(\mathfrak {u}(x)\) corresponds to computing the eigenvalues of an \(n\times n\) matrix \(\mathscr {C}\), called colleague matrix (Good 1961). We use the form of the colleague matrix described in Casulli and Robol (2021):

$$\begin{aligned} \mathscr {C}=\frac{1}{2}\left[ \begin{array}{ccccc} 0 &{}\quad 1 &{}\quad 0 &{}\quad \ldots &{}\quad 0 \\ 1 &{}\quad 0 &{}\quad \ddots &{}\quad &{}\quad \vdots \\ 0 &{}\quad \ddots &{}\quad \ddots &{}\quad 1 &{}\quad 0 \\ \vdots &{}\quad \ddots &{}\quad 1 &{}\quad 0 &{}\quad \sqrt{2} \\ 0 &{}\quad \ldots &{}\quad 0 &{}\quad \sqrt{2} &{}\quad 0 \\ \end{array} \right] - \frac{1}{2c_n} \left[ \begin{array}{c} 1 \\ 0 \\ \vdots \\ 0 \\ \end{array} \right] \left[ \begin{array}{ccccc} c_{n-1} &{}\quad c_{n-2} &{}\quad \ldots &{}c_1 &{}\quad \sqrt{2}c_0 \\ \end{array} \right] . \end{aligned}$$
(22)

The computation of the roots of a polynomial using the colleague matrix and a backward stable eigenvalue algorithm, such as the QR algorithm, is backward stable, provided that the 2-norm of the polynomial is moderate (see Noferini and Pérez 2017).

5 True anomalies and trigonometric polynomials

The same steps described in Sect. 4 can be applied to look for the critical points of the squared distance function expressed in terms of the true anomalies \(f_1\), \(f_2\). Note that using true anomalies allows to deal with both bounded and unbounded trajectories (Sitarski 1968; Gronchi 2005).

We write the system

$$\begin{aligned} \nabla d^2(f_1,f_2) = \textbf{0} \end{aligned}$$

as

$$\begin{aligned} \left\{ \begin{aligned}&\alpha \cos f_1 + \beta \sin f_1 + \gamma = 0, \\&\kappa \cos ^2 f_1 + \lambda \sin f_1\cos f_1 + \mu \cos f_1 + \nu \sin f_1 + \kappa =0, \end{aligned} \right. \end{aligned}$$
(23)

where

$$\begin{aligned} \begin{aligned} \alpha&= p_1(1+e_2\cos f_2)(K\sin f_2 - M(e_2+\cos f_2)) + p_2e_1e_2\sin f_2, \\ \beta&= p_1(1+e_2\cos f_2)(L\sin f_2 - N(e_2+\cos f_2)), \\ \gamma&= p_2e_2\sin f_2, \\ \kappa&= -p_2e_1(L\cos f_2 + N\sin f_2), \\ \lambda&= p_2e_1(K\cos f_2 + M\sin f_2), \\ \mu&= -p_2(1+e_1^2)(L\cos f_2 + N\sin f_2), \\ \nu&= p_1e_1(1+e_2\cos f_2) + p_2(K\cos f_2 + M\sin f_2). \\ \end{aligned} \end{aligned}$$

We also set

$$\begin{aligned} \begin{aligned}&\tilde{\kappa } = p_2(L\cos f_2+N\sin f_2), \\&\tilde{\lambda } = p_2(K\cos f_2+M\sin f_2), \end{aligned} \end{aligned}$$

so that

$$\begin{aligned} \kappa = -e_1\tilde{\kappa } = \frac{e_1}{1+e_1^2}\mu , \qquad \lambda = e_1\tilde{\lambda }, \qquad \nu = p_1e_1(1+e_2\cos f_2) + \tilde{\lambda }. \end{aligned}$$

Inserting relation

$$\begin{aligned} \sin f_1 = -\frac{1}{\beta }(\alpha \cos f_1 + \gamma ) \end{aligned}$$
(24)

into \(\cos ^2f_1+\sin ^2f_1-1 = 0\) and into the second equation of (23), we obtain

$$\begin{aligned} \left\{ \begin{aligned}&(\alpha ^2+\beta ^2)\cos ^2 f_1 + 2\alpha \gamma \cos f_1 + \gamma ^2-\beta ^2 = 0, \\&(\beta \kappa - \alpha \lambda )\cos ^2 f_1 + (\beta \mu - \lambda \gamma -\alpha \nu )\cos f_1 + \beta \kappa -\gamma \nu = 0. \\ \end{aligned} \right. \end{aligned}$$
(25)

As in Sect. 4, we consider the Sylvester matrix of the two polynomials in (25)

$$\begin{aligned} \mathscr {T} = \left[ \begin{array}{cccc} \alpha ^2+\beta ^2 &{}\quad 0 &{}\quad \beta \kappa - \alpha \lambda &{}\quad 0 \\ 2\alpha \gamma &{}\quad \alpha ^2+\beta ^2 &{}\quad \beta \mu - \lambda \gamma -\alpha \nu &{}\quad \beta \kappa - \alpha \lambda \\ \gamma ^2-\beta ^2 &{}\quad 2\alpha \gamma &{}\quad \beta \kappa -\gamma \nu &{}\quad \beta \mu - \lambda \gamma -\alpha \nu \\ 0 &{}\quad \gamma ^2-\beta ^2 &{}\quad 0 &{}\quad \beta \kappa -\gamma \nu \\ \end{array} \right] \end{aligned}$$

and define

$$\begin{aligned} \mathscr {H}(f_2) = \det \mathscr {T}, \end{aligned}$$

that we are able to factorize. In particular, we can write

$$\begin{aligned} \mathscr {H}(f_2) = (1+e_2\cos f_2)^2\beta ^2h(f_2), \end{aligned}$$

where

$$\begin{aligned} \begin{aligned} h(f_2)&= \tilde{\beta }^4\xi ^2\mu ^2(4\eta ^2-1) +2\tilde{\beta }^3\xi \mu \left[ \lambda \gamma +\alpha \nu -2\eta (\alpha \lambda +\gamma \nu )\right] \\&\,\quad +\tilde{\beta }^2(\alpha ^2-\gamma ^2)\left[ \lambda ^2-\nu ^2+\mu ^2(4\eta ^2-1)\right] \\&\,\quad -2\mu \tilde{\beta }\tilde{\alpha }^2\xi ^2\left[ \tilde{\alpha }(\lambda \eta -\nu )-3\eta e_1^3 p_1\gamma \right] + \mu ^2\tilde{\alpha }^2\left[ \gamma (1-2\eta e_1)- \xi \eta \tilde{\alpha }\right] ^2\\&\,\quad -2\mu \tilde{\beta }p_1e_1(1-e_1^2)\eta \gamma ^2\left[ 3e_1\tilde{\alpha }\xi -\gamma (1-e_1^2)\right] -(\alpha ^2-\gamma ^2)(\nu \tilde{\alpha }+p_1e_1^2\gamma )^2, \end{aligned} \end{aligned}$$
(26)

with

$$\begin{aligned} \eta&= \frac{e_1}{1+e_1^2},&\xi&= 1+e_2\cos f_2,\\ \tilde{\alpha }&= p_1[K\sin f_2-M(e_2+\cos f_2)],&\tilde{\beta }&= p_1[L\sin f_2-N(e_2+\cos f_2)]. \end{aligned}$$

We can show that \(h(f_2)\) has degree 8 in \((\cos f_2, \sin f_2)\). The related computations are displayed in Appendix B.

Let us set

$$\begin{aligned} \mathfrak {h}(x,y) = h(f_2), \end{aligned}$$

where

$$\begin{aligned} x=\cos f_2, \qquad y = \sin f_2. \end{aligned}$$

We find that

$$\begin{aligned} \mathfrak {h}(x,y) = \sum _{j=0}^6 h_j(x) y^j \end{aligned}$$

for some polynomial coefficients \(h_j\) such that

$$\begin{aligned} \begin{aligned}&\deg h_0 = 8, \quad \deg h_1 = 7, \quad \deg h_2 = 6,\\&\deg h_3 = 5, \quad \deg h_4 = 4, \quad \deg h_5 = 3, \quad \deg h_6 = 2. \end{aligned} \end{aligned}$$

Then, we consider the system

$$\begin{aligned} \left\{ \begin{aligned}&\mathfrak {h}(x,y) = 0, \\&x^2+y^2 -1 = 0. \\ \end{aligned} \right. \end{aligned}$$
(27)

Proceeding as in Sect. 4, we can substitute \(\mathfrak {h}(x,y)\) with

$$\begin{aligned} \tilde{\mathfrak {h}}(x,y) = \mathfrak {a}(x)y + \mathfrak {b}(x), \end{aligned}$$
(28)

with

$$\begin{aligned} \begin{aligned} \mathfrak {a}(x)&= a_0(x)+x^2a_2(x)+x^4a_4(x), \\ \mathfrak {b}(x)&= b_0(x)+x^2b_2(x)+x^4b_4(x)+x^6b_6(x), \\ \end{aligned} \end{aligned}$$

where

$$\begin{aligned} \begin{aligned} a_0&= h_1+h_3+h_5,&a_2&= -h_3-2h_5,&a_4&= h_5,{} & {} \\ b_0&= h_0+h_2+h_4+h_6,&b_2&= -h_2-2h_4-3h_6,&b_4&= h_4+3h_6,&b_6&=-h_6. \end{aligned} \end{aligned}$$

We apply resultant theory to eliminate the dependence on y as in Sect. 4 and obtain a univariate polynomial \(\mathfrak {v}\) of degree 16. The real roots of \(\mathfrak {v}\) with absolute value \(\le 1\) correspond to the values of \(\cos f_2\) we are searching for. We compute \(\sin f_2\) from (28) and substitute \(\cos f_2\) and \(\sin f_2\) in (25). Finally, \(\cos f_1\) and \(\sin f_1\) are found by solving (25) and using (24).

5.1 Angular shifts

Also for the method presented in this section, we consider the application of an angular shift. If we define the new shifted angle \(v_2\) by

$$\begin{aligned} v_2 = f_2-s_2, \end{aligned}$$

for some \(s_2\in [0,2\pi )\), the coefficients of the polynomial (26) written in terms of \(v_2\) are derived following the computations of Appendix C. Then, following a procedure analogous to Sect. 5, we find the values of \(v_2\) and shift back to get \(f_2\). Finally, we can apply an angular shift also to the angle \(f_1\) when solving system (25). Defining the shifted angle as

$$\begin{aligned} v_1 = f_1-s_1, \end{aligned}$$

for \(s_1\in [0,2\pi )\), system (25) becomes

$$\begin{aligned} \left\{ \begin{aligned}&A\cos v_1 + B\sin v_1 + C = 0, \\&D\cos ^2 v_1 + E\sin v_1\cos v_1 + F\cos v_1 + G\sin v_1 + H =0, \end{aligned} \right. \end{aligned}$$
(29)

where

$$\begin{aligned} \begin{aligned} A&= \alpha \cos s_1+\beta \sin s_1, \\ B&= \beta \cos s_1-\alpha \sin s_1, \\ C&= \gamma , \\ D&= \kappa \cos ^2s_1-\kappa \sin ^2s_1+2\lambda \sin s_1\cos s_1, \\ E&= \lambda \cos ^2s_1-\lambda \sin ^2s_1-2\kappa \sin s_1\cos s_1, \\ F&= \mu \cos s_1+\nu \sin s_1, \\ G&= \nu \cos s_1-\mu \sin s_1, \\ H&= \kappa \sin ^2s_1-\lambda \sin s_1\cos s_1+\kappa , \end{aligned} \end{aligned}$$

with \(\alpha , \beta , \gamma , \kappa , \lambda , \mu , \nu \) defined at the beginning of this section.

6 Numerical tests

We have developed Fortran codes for each of the methods presented in this paper. We denote these methods with (OE, OES, TE, TEC, TT, TTS), see Table 1. Moreover, we denote by (OT) the method presented in Gronchi (2005). Numerical tests have been carried out for pairs of bounded trajectories to compare the different methods.

Taking the NEA catalogue available at https://newton.spacedys.com/neodys/, we applied these methods to compute the critical points of the squared distance between each NEA and the Earth, and between all possible pairs of NEAs. We applied a few simple checks to detect errors in the results:

  • Weierstrass check (W): for each pair of trajectories we have to find at least one maximum and one minimum point;

  • Morse check (M): for each pair of trajectories, let N be the total number of critical points, and M and m be the number of maximum and minimum points, respectively. Then (assuming \(d^2\) is a Morse function) we must have \(N=2(M+m)\);

  • Minimum distance check (\(d_{\textrm{min}}\)): we sample the two trajectories with k uniformly distributed points each (we used \(k=10\)), and compute the distance between each pair of points. We check that the minimum value of d computed through this sampling is greater than the value of \(d_{\textrm{min}}\) obtained with our methods.

For each method a small percentage of cases fail due to some of the errors above. However, in our tests, for each pair of orbits, at least one method passes all three checks.

The angular shifts (see Sects. 3.1,  5.1) allow us to solve the majority of detected errors for the methods of Sects. 3 and 5 without shift (OE, TT). Applying a shift could also be a way to solve most of the errors detected by the method of Sect. 4 (TE, TEC).

Some data on the detected errors for each method are reported in Table 1. Here, we show the percentages of cases failing some of the three checks described above. We note that the NEA catalogue contains 31,563 NEAs with bounded orbits (to the date of February 25, 2023). Therefore, for the NEA–Earth test we are considering 31,563 pairs of orbits, while for the NEA–NEA test the number of total pairs is 498,095,703. From Table 1, we see that the method TE is improved with Chebyshev’s polynomials (TEC). In the same way, the methods OE, TT are improved by applying angular shifts in case of detected errors (OES, TTS). Indeed, the method TTS turns out to be the most reliable for the computation of \(d_{\textrm{min}}\).

Table 1 Percentages of detected errors with each method applied to the computation of all critical points between all NEAs and the Earth and between all pairs of NEAs

Two additional ways to check in particular the computation of \(d_{\textrm{min}}\) are discussed below.

6.1 Reliability test for \(d_{\textrm{min}}\)

Although all the presented methods allow us to find all the critical points of \(d^2\), we are particularly interested in the correct computation of the minimum distance \(d_{\textrm{min}}\). For this reason, we introduce two different tests to check whether the computed values of \(d_{\textrm{min}}\) are reliable.

The first test is based on the results of Gronchi and Valsecchi (2013), where the authors found optimal upper bounds for \(d_{\textrm{min}}\) when one orbit is circular. Let us denote with \({{\mathcal {A}}}_1\) and \({{\mathcal {A}}}_2\) the two trajectories. Assume that \({{\mathcal {A}}}_2\) is circular with orbital radius \(r_2\), and call \(q_1,e_1,i_1,\omega _1\) the pericenter distance, eccentricity, inclination and argument of pericenter of \({{\mathcal {A}}}_1\). Moreover, set

$$\begin{aligned} {{\mathcal {C}}} = [0, 1] \times [0, \pi /2], \qquad {{\mathcal {D}}} = [0, q_\textrm{max}] \times [0,\pi /2], \end{aligned}$$
(30)

where we used \(q_{\textrm{max}}=1.3\), which is the maximum perihelion distance of near-Earth objects. Then, for each choice of \((q_1,\omega _1)\in {{\mathcal {D}}}\) we have

$$\begin{aligned} \max _{(e_1,i_1)\in {{\mathcal {C}}}}d_{\textrm{min}}= \max \{r_2-q_1,\delta (q_1,\omega _1)\}, \end{aligned}$$
(31)

where \(\delta (q_1,\omega _1)\) is the distance between \({{\mathcal {A}}}_1\) and \({{\mathcal {A}}}_2\) with \(e_1=1, i_1=\pi /2\):

$$\begin{aligned} \delta (q,\omega ) = \sqrt{(\xi -r_2\sin \omega )^2 + \left( \frac{\xi ^2 - 4q^2}{4q} + r_2\cos \omega \right) ^2}\,, \end{aligned}$$
(32)

with \(\xi =\xi (q,\omega )\) the unique real solution of

$$\begin{aligned} x^3 + 4q(q+\cos \omega )x - 8r_2q^2\sin \omega = 0. \end{aligned}$$

We compare this optimal bound with the maximum values of \(d_{\textrm{min}}\) computed with the method OE, for a grid of values in the \((q_1,\omega _1)\) plane. The results are reported in Fig. 1. Here, we see that the maximum values of \(d_{\textrm{min}}\) obtained through our computation appear to lie on the grey surface corresponding to the graph of \(\displaystyle {\max _{{\mathcal {C}}}d_{\textrm{min}}(q_1,\omega _1)}\) defined in (31). This test confirms the reliability of our computations. Similar checks were successful with all the methods of Table 1.

Fig. 1
figure 1

Comparison between the graph of \(\max _{(e_1,i_1)}d_{\textrm{min}}(q,\omega )\) defined in (31) and the maximum values of \(d_{\textrm{min}}\) computed with the algorithm of Sect. 3 for a grid of values of \((q_1,\omega _1)\)

To test our results also in case of two elliptic orbits, we consider the following bound introduced in Gronchi and Niederman (2020) for the nodal distance \(\delta _{\textrm{nod}}\) defined below. Let

where \(q_2\), \(e_2\) are the pericenter distance and eccentricity of \({{\mathcal {A}}}_2\), and , are the mutual arguments of pericenter (see Gronchi and Niederman 2020).

We introduce the ascending and descending nodal distances

The (minimal) nodal distance \(\delta _{\textrm{nod}}\) is defined as

$$\begin{aligned} \delta _{\textrm{nod}}= \min \bigl \{|d_{\textrm{nod}}^+|, |d_{\textrm{nod}}^-|\bigr \}. \end{aligned}$$
(33)

Set

$$\begin{aligned} {{\mathcal {C}}}' = [0, 1] \times [0, \pi ]. \end{aligned}$$

For each choice of \((q_1,\omega _1)\in {{\mathcal {D}}}\), defined as in (30), we have

(34)

where, denoting by \(Q_2\) the apocenter distance of \({{\mathcal {A}}}_2\) and by \(p_2 = q_2(1+e_2)\) its conic parameter,

$$\begin{aligned}{} & {} u^\omega _{\textrm{int}}(q,\omega ) = p_2 - q, \\{} & {} u^\omega _{\textrm{ext}}(q,\omega ) = \min \Bigl \{ \frac{2q}{1-\cos \omega } - \frac{p_2}{1-\hat{\xi }'_*},\ \frac{2q}{1+\cos \omega } - q_2\Bigr \}, \\{} & {} u^\omega _{\textrm{link}}(q,\omega ) = \min \left\{ Q_2 - \frac{q(1+\hat{e}_*)}{1+\hat{e}_*\cos \omega }, \frac{2q}{1-\cos \omega }-q_2 \right\} , \end{aligned}$$

with

$$\begin{aligned} \hat{\xi }'_* = \min \{ \xi _*',e_2\},\qquad \xi '_*(q,\omega ) = \frac{4q\cos \omega }{p_2\sin ^2\omega + \sqrt{p_2^2\sin ^4\omega +16q^2\cos ^2\omega }}, \end{aligned}$$

and

$$\begin{aligned}&\hat{e}_* = \max \bigl \{0,\min \{e_*,1\}\bigr \},\\&e_*(q,\omega ) = \frac{2(p_2-q(1-e_2^2))}{q(1-e_2^2) + \sqrt{q^2(1-e_2^2)^2 + 4p_2\cos ^2\omega (p_2-q(1-e_2^2))}}. \end{aligned}$$

We compare the computed values of \(d_{\textrm{min}}\) with the bound (34) on the maximum nodal distance. The results are displayed in Fig. 2 where, for four different values of \(e_2\), the grey surface represents the bound of Gronchi and Niederman (2020), while the black dots correspond to the maximum value of \(d_{\textrm{min}}\) for a grid in the \((q_1,\omega _1)\) plane computed with the method OE. Since the value of \(\delta _{\textrm{nod}}\) is always greater than or equal to the value of \(d_{\textrm{min}}\), for the test to be satisfied, we need all the black dots to fall below or lie on the grey surface. From Fig. 2, we see that this is indeed what happens.

Similar checks done with the methods OT, OE, OES, TT, TTS were successful.

Fig. 2
figure 2

Comparison of the maximum MOID obtained with the method of Sect. 3 and the bound on the nodal distance found in Gronchi and Niederman (2020). These plots were drawn using values of \(e_2\) equal to 0.2 (top-left), 0.3 (top-right), 0.4 (bottom-left) and 0.5 (bottom-right)

7 The planar case

Let us consider the case of two coplanar conics parametrized by the true anomalies \(f_1\), \(f_2\). Then, \((f_1, f_2)\) is a critical point of \(d^2\) iff \(d^2(f_1, f_2)=0\) or the tangent vectors

$$\begin{aligned} \varvec{\tau }_1(f_1) = \frac{\partial {{\mathcal {X}}}_1}{\partial f_1},\qquad \varvec{\tau }_2(f_2) = \frac{\partial {{\mathcal {X}}}_2}{\partial f_2} \end{aligned}$$

to the first and second conic at \({{\mathcal {X}}}_1(f_1)\)   and   \({{\mathcal {X}}}_2(f_2)\), respectively, are parallel. If one trajectory, say the second one, is circular, then the tangent vector \(\varvec{\tau }_2\) is orthogonal to the position vector \({{\mathcal {X}}}_2\) for any value of \(f_2\). Therefore, to find critical points that do not correspond to trajectory intersections, it is enough to look for values of \(f_1\) such that \(\textbf{r}_1\cdot \varvec{\tau }_1=0\). By symmetry, we can write

$$\begin{aligned} {{\mathcal {X}}}_1 = \begin{pmatrix} r_1\cos f_1\\ r_1\sin f_1 \end{pmatrix}, \qquad \text {with}\quad r_1 = \frac{p_1}{1+e_1\cos f_1}, \end{aligned}$$

that is we can assume \(\omega _1 = 0\). Thus, up to a multiplicative factor, we have

$$\begin{aligned} \varvec{\tau }_1 = \begin{pmatrix} -\sin f_1\\ \cos f_1+e_1 \end{pmatrix}, \end{aligned}$$

so that

$$\begin{aligned} \textbf{r}_1\cdot \varvec{\tau }_1 = \frac{p_1e_1\sin f_1}{1+e_1\cos f_1} = 0 \end{aligned}$$

is satisfied iff \(f_1 = 0,\pi \). Therefore, in general, we have the four critical points

$$\begin{aligned} \big ({\bar{f}}_1,{\bar{f}}_2 \big ) = (0,0), (0,\pi ), (\pi ,0), (\pi ,\pi ). \end{aligned}$$

We may have at most two additional critical points that correspond to trajectory intersections, see Gronchi and Tommei (2007, Sect. 7.1). In conclusion, the maximum number of critical points with a circular and an elliptic trajectory in the planar case is 6.

We consider now the case of two ellipses. The position vectors can be written as

$$\begin{aligned} {{\mathcal {X}}}_1 = \begin{pmatrix} r_1\cos f_1\\ r_1\sin f_1 \end{pmatrix}, \qquad \text {with}\quad r_1 = \frac{p_1}{1+e_1\cos f_1} \end{aligned}$$

and

$$\begin{aligned} {{\mathcal {X}}}_2 = \begin{pmatrix} r_2\cos (f_2+\omega _2)\\ r_2\sin (f_2+\omega _2) \end{pmatrix}, \qquad \text {with}\quad r_2 = \frac{p_2}{1+e_2\cos f_2}. \end{aligned}$$

Up to a multiplicative factor, we have

$$\begin{aligned} \varvec{\tau }_1 = \begin{pmatrix} -\sin f_1\\ \cos f_1+e_1 \end{pmatrix}, \hspace{28.45274pt}\varvec{\tau }_2 = \begin{pmatrix} -\sin (f_2+\omega _2)-e_2\sin \omega _2\\ \cos (f_2+\omega _2)+e_2\cos \omega _2 \end{pmatrix}. \end{aligned}$$

The critical points that do not correspond to trajectory intersections are given by the values of \(f_1, f_2\) such that \(\varvec{\tau }_1, \varvec{\tau }_2\) are parallel and both orthogonal to \({{\mathcal {X}}}_2-{{\mathcal {X}}}_1\). These two conditions lead to the system

figure a

Multiplying (35) by \(r_2\) and subtracting (36) we get

$$\begin{aligned} p_1e_1(1+e_2\cos f_2)\sin f_1+p_2e_2(1+e_1\cos f_1)(\cos f_1\sin \omega _2-\sin f_1\cos \omega _2+e_1\sin \omega _2)=0. \end{aligned}$$
(37)

Equations (35) and (37) can be written as

figure b
Table 2 Cometary orbital elements of a pair of coplanar elliptic orbits giving 10 critical points
Fig. 3
figure 3

Level curves of the squared distance for the case reported in Table 2. The position of the critical points is highlighted: saddle points are represented by black asterisks, while the red and blue crosses correspond to maximum and minimum points, respectively

Table 3 Critical points and critical values for the pair of orbits displayed in Table 2

where

$$\begin{aligned} \alpha&= \sin (\omega _2-f_1)+e_1\sin \omega _2,\\ \beta&= \cos (\omega _2-f_1)+e_1\cos \omega _2,\\ \mu&= p_1e_1e_2\sin f_1,\\ \delta&= p_1e_1\sin f_1+p_2e_2(1+e_1\cos f_1)(\cos f_1\sin \omega _2-\sin f_1\cos \omega _2+e_1\sin \omega _2). \end{aligned}$$

From (38) we obtain

$$\begin{aligned} \sin f_2 = -\frac{\alpha }{\beta }(\cos f_2+e_2), \end{aligned}$$

which is replaced into relation \(\cos ^2f_2+\sin ^2f_2-1=0\) to give

$$\begin{aligned} \big (\alpha ^2+\beta ^2 \big )\cos ^2f_2+2\alpha ^2e_2\cos f_2+e_2^2\alpha ^2-\beta ^2 = 0. \end{aligned}$$
(40)

Moreover, after replacing in (40)

$$\begin{aligned} \cos f_2 = -\frac{\delta }{\mu }, \end{aligned}$$

which follows from (39), we obtain

$$\begin{aligned} \big (\alpha ^2+\beta ^2 \big )\delta ^2-2e_2\alpha ^2\delta \mu +\mu ^2\big (e_2^2\alpha ^2-\beta ^2 \big ) = 0. \end{aligned}$$
(41)

Since

$$\begin{aligned} \alpha ^2+\beta ^2=1+e_1^2+2e_1\cos f_1, \end{aligned}$$

the trigonometric polynomial in (41) has, in general, degree 5 in \(\cos f_1\), \(\sin f_1\). Therefore, we cannot have more than 10 critical points which do not correspond to trajectory intersections. Then, the maximum number of critical points of \(d^2\) (including intersections) for two elliptic orbits in the planar case is at most 12. However, we remark that this bound has never been reached in our numerical tests, where we got at most 10 critical points that we think is the maximum number. This conjecture adds a new question to Problem 8 in Albouy et al. (2012).

In Table 2, we write a set of orbital elements giving 10 critical points. We draw the level curves of \(d^2\) in Fig. 3, as function of the eccentric anomalies \(u_1, u_2\), where the position of each critical point is highlighted: we use an asterisk for saddle points, and crosses for local extrema. Finally, the critical points, the corresponding values of d and their type (minimum, maximum, saddle) are displayed in Table 3.

8 Conclusions

In this work, we investigate different approaches for the computation of the critical points of the squared distance function \(d^2\), with particular care for the minimum values. We focus on the case of bounded trajectories. Two algebraic approaches are used: the first employs ordinary polynomials, the second trigonometric polynomials. In both cases, we detail all the steps to reduce the problem to the computation of the roots of a univariate polynomial of minimal degree (that is 16, in the general case). The different methods are compared through numerical tests using the orbits of all the known near-Earth asteroids. We also perform some reliability tests of the results, which make use of known optimal bounds on the orbit distance. Finally, we improve the theoretical bound on the number of critical points in the planar case, and refine the related conjecture.