Computing the Closest Approach Distance of Two Ellipsoids

: This paper presents two practical methods for computing the closest approach distance of two ellipsoids in their inter-center direction. The closest approach distance is crucial for collision handling in the dynamic simulation of rigid and deformable bodies approximated with ellipsoids. To ﬁnd the closest approach distance, we formulate a set of equations for two ellipsoids contacting each other externally in terms of the inter-center distance, contact point, and normal vector. The equations are solved robustly and efﬁciently using a hybrid of the ﬁxed-point iteration method and bisection method with root bracketing, and a hybrid of Newton’s method and the bisection method. In addition to a stopping criterion expressed with the progress of the solution, we introduce a novel criterion expressed in terms of the error in distance. This criterion can be effectively employed in real-time applications such as computer games by allowing an unnoticeable error. Experimental results demonstrate the robustness and efﬁciency of the proposed methods in various experiments.


Introduction
Recently, several techniques have been proposed to increase the speed of physics-based dynamic simulation by approximating rigid and deformable bodies with ellipsoids for interactive applications such as computer games [1][2][3]. Computing the closest approach distance between two ellipsoids in their inter-center direction is a key technique for collision handling among ellipsoids.
Given the positions and orientations of two ellipsoids, their overlap can be determined in a relatively easy manner by examining the signs of the solutions of their quartic characteristic equation without obtaining the actual solutions [4][5][6][7]. However, it is not easy to separate two overlapping ellipsoids. Position-based dynamics with ellipsoids [1] takes an approach that translates two ellipsoids outward along their inter-center direction by the closest approach distance to make them contact each other externally. To find the closest approach distance, a set of equations is formulated intuitively in terms of the inter-center distance, contact point, and contact normal vector. However, there is an error in the derivation of this solution; consequently, the solution is correct only for two spheres. In this paper, we rectify this error to find the closest approach distance correctly and intuitively. In [2,3], the method to compute the closest approach distance is not described.
The closest approach distance between two ellipsoids also plays important roles in the simulation of liquid crystals and colloidal systems [8][9][10][11][12]. In [10], an indirect formulation was introduced with the optimization of the elliptic contact function proposed in [8,9]. However, the derivation was complicated, and the numerical solution method was not addressed. In the method proposed in [12], the golden section search is employed with an analytic method [11] that computes the closest approach distance between two ellipses formed by the cross-section of two ellipsoids with a plane rotating about the line joining their centers. However, this method is considerably slow. This paper presents two robust and efficient methods for computing the closest approach distance between two ellipsoids within a user-specified tolerance. The proposed methods are based on the intuitive approach introduced in position-based dynamics with ellipsoids [1]. We formulate the problem with a set of conditions in terms of the inter-center distance, contact point, and contact normal vector of two externally-contacting ellipsoids. The resulting equations are solved robustly and efficiently using a hybrid of the fixed-point iteration method and bisection method with root bracketing, and a hybrid of Newton's method and the bisection method. In addition to a stopping criterion expressed with the change of the solution in a single solver iteration, we introduce a novel criterion expressed in terms of the actual error in distance. This can be effectively employed to increase the efficiency of the proposed methods in real-time applications such as computer games by allowing unnoticeable interferences between ellipsoids.

Problem
Two ellipsoids can contact each other externally at a point by moving the center of one ellipsoid along their inter-center direction. The inter-center distance d in this circumstance is the closest approach distance of the two ellipsoids in their inter-center direction. The objective of the study was to develop a method that computes the distance d efficiently.
To formulate the closest approach distance, we first describe the shapes of two ellipsoids: e 1 and e 2 . Each ellipsoid e i has three pairwise perpendicular unit axes of symmetry denoted by e a i , e b i , and e c i , and the corresponding principal radii denoted by a i , b i , and c i in decreasing order. For convenience of derivation, we introduce the following quadratic functions for the ellipsoids: i is a symmetric matrix and R i = [e a i |e b i |e c i ] is a 3 × 3 rotation matrix. Thus, the shape of the ellipsoid e i centered at the origin can be described by the point x that satisfies xE i x T = 1.
The closest approach distance of two ellipsoids in their inter-center direction is invariant under translation. Given two ellipsoids, we displace both ellipsoids at the same time such that one ellipsoid is centered at the origin and the other ellipsoid maintains its relative direction and distance. We assume that e 1 is centered at the origin and n is the unit direction vector from the center of e 1 to the center of e 2 . When the two ellipsoids touch each other externally at a contact point x by approaching in the direction n with the inter-center distance d, the center of e 2 is apart from the center of e 1 by dn. At this moment, x should be a point on e 1 and e 2 . Thus, x and d should satisfy the following two conditions represented using the quadratic functions given in Equation (1): In addition, for the two ellipsoids to contact each other externally at x, the tangent planes of e 1 and e 2 at x should be parallel with opposite normal directions. That is, the gradient vectors of e 1 and e 2 at x should be parallel with opposite directions. Thus, the following condition for the gradient vectors should also be satisfied: where ∇ denotes the spatial derivative with respect to x, and u/(u − 1) ∈ (−∞, 0] makes the gradient vectors have opposite directions. Here, u/(u − 1) was adopted, unlike λ ∈ (−∞, 0] in [1], to make the range of u finite, such that a bracketing method can be employed for root finding. Finally, the computation of the closest approach distance d requires the determination of u and x that satisfies all three conditions given in Equations (2)-(4).

Solution Method
The substitution of the gradient vectors of the quadratic functions given in Equation (1) into Equation (4) yields Manipulating Equation (5) for x, we can obtain where w(u) is introduced for compact representation of x: In Equation (6), x is dependent on u and d. However, we consider x as a function of only u for the moment with the assumption that d is known. As illustrated in Figure 1, x(u) moves along a curve that starts from the origin (the center of e 1 ) to dn (the center of e 2 ) as u varies from 0 to 1. Along this curve, the gradient vector ∇e 1 (x) is parallel to ∇e 2 (x − dn) in the opposite direction. The contact point should be on both ellipsoids. The substitution of Equation (6) into Equations (2) and (3) yields Here, to derive Equation (9) in a compact form, Equation (5) was rearranged as (x − dn) = (u − 1)/uE −1 2 E 1 x and then applied to Equation (3) with the property E T i = E i . By subtracting each side of Equation (9) from Equation (8), we can eliminate d, and thus we no longer need the assumption that d is known. This results in the following sextic equation of u ∈ (0, 1]: Once u is computed, w can be obtained from Equation (7), d from Equations (8) and (9), and finally x from Equation (6).
To solve Equation (10) for u, we propose two methods based on fixed-point iteration and Newton's method. The former is easy to implement, but converges slowly for an accurate solution. The latter requires the derivative f (u) as well as the function value f (u), but converges quickly in general. However, when applied to real-time applications with an actual error tolerance that allows a relatively large but unnoticeable error as suggested in Section 2.3, the former converges as quickly as the latter.
A fixed-point iteration method can be obtained by manipulating Equation (10) with respect to u and exploiting w(u) at the previous iteration: In addition, the root bracketing property of the bisection method can be adopted because u ∈ [0, 1). Consequently, we can employ a hybrid of the fixed-point iteration and the bisection method as in Newton's method [13] to guarantee the convergence. In contrast to our derivation, a similarity transform was incorrectly applied in [1] to an equation, corresponding to Equation (10) but formulated with λ = u/(u − 1), so that it became quadratic and could be solved analytically. However, this condition is true only for the case of two spheres. In [2,3], this mistake was rectified, and fixed-point iteration was employed to address the case of two ellipsoids. However, it was not described because collision detection between two ellipsoids was not the major concern. Furthermore, the formulation with λ does not allow root bracketing; therefore, a hybrid approach with the bisection method cannot be employed.
To obtain an accurate solution of Equation (10), Brent's method [13] can be employed with the function value f (u) only, as suggested in [9]. However, for better convergence, we employ a hybrid of Newton's method and the bisection method with root bracketing [13], which exploits the derivative f (u) as well as the function value f (u). To this end, we need an analytic form of f (u). By employing the differentiation rule ∂(A −1 ) = −A −1 (∂A)A −1 [14], we obtain where E 21 = (E 2 − E 1 ) and E u = (1 − u)E 1 + uE 2 .

Initial Guess and Stopping Criteria
A good initial guess is considerably important in reducing the number of solver iterations. From Figure 1, u = 0.5 is a good initial guess because it is the exact solution when two ellipsoids are actually spheres with the same radius. For two spheres with different radii a 1 and a 2 , u = a 1 /(a 1 + a 2 ) is the exact solution, and thus it becomes a good initial guess for more general cases. This initial guess was employed in all the experiments.
For a stopping criterion, we can simply adopt the following popular one: This determines whether the change of u in the i-th iteration is less than a user-specified tolerance u . To reduce the number of iterations further, we introduce an additional actual error tolerance as a stopping criterion. The closest approach distance d can be obtained from u using Equations (8) and (9). Here, d should be positive when the two ellipsoids touch each other externally in the direction n. Let d 1 and d 2 be the distances computed using Equations (8) and (9), respectively. Note that d 1 and d 2 can be different because of the numerical error in u. The contact points x 1 and x 2 on the two ellipsoids can be obtained by substituting u, d 1 , and d 2 into Equation (6). Thus, we can employ a stopping criterion that determines whether the distance between the two contact points is within a user-specified tolerance at the i-th iteration: x where r min is the minimum radius of the two ellipsoids. In real-time applications such as computer games, users generally do not notice interferences between ellipsoids with x less than 1%. Consequently, the criterion given in Equation (14) is effective in reducing the number of iterations while allowing an unnoticeable numerical error with slight additional computation.

Experimental Results
We propose two methods to compute the closest approach distance of two ellipsoids. One method employs a hybrid of the bisection method with Newton's method, and the other with fixed-point iteration. We call the former hybrid Newton's method and the latter the hybrid fixed-point iteration method. In this section, we describe a performance comparison of four methods: (1) hybrid Newton's method, (2) hybrid fixed-point iteration method, (3) Brent's method with the elliptic contact potential [9], and (4) cross-section search [12] in various examples. The proposed methods were implemented using C++ and the Eigen library (eigen.tuxfamily.org) to perform the vector and matrix operations. All of the experiments were performed using a workstation equipped with a 2.3 GHz 18-core Intel Xeon W processor and 128 GB 2666 MHz DDR4 RAM.
The first experiment was conducted to test the number of solver iterations and the computation times for 10 million pairs of randomly generated ellipsoids. The ratio between the maximum and minimum radii of each ellipsoid was restricted to less than γ, and the ratio between the maximum radii in a pair of ellipsoids was restricted to less than Γ. The orientation of an ellipsoid and the inter-center direction between a pair of ellipsoids were generated randomly without any restriction. For robustness of physics-based simulation, γ = 2 was used in [1] and γ = 5 in [2,3]. Figure 2 shows the distributions of the numbers of solver iterations required for u = 10 −8 for the four methods with γ = 3 and Γ = 3. The average and maximum number of solver iterations and the average computation time are listed in Table 1. The computation time was measured using a single core in this experiment. The hybrid Newton's method performed better than the others in all aspects.
The error in the analytic method for the closest approach distance of two ellipses increased as γ increased [11]. Correspondingly, the error in the cross-section search [12] also increased, regardless of the number of solver iterations in the golden section search that found the angle of the cross section resulting in the closest approach distance of two ellipsoids. In contrast, the other methods computed the closest approach distance within a user-specified tolerance even with a large γ. However, the number of solver iterations increased as γ increased. This result was verified with the second experiment, in which the closest approach distances were computed for each of the 1 million pairs of ellipsoids generated randomly with γ increasing from 1 to 200 and Γ fixed at 3. For the stopping criterion, we employed Equation (13) with u = 10 −8 and the maximum number of solver iterations set to 100. Figure 3 shows the maximum and average number of solver iterations. In the traditional fixed-point iteration method, the number of solver iterations exceeded 100 when γ became larger than 7. However, the hybrid fixed-point iteration method was robust, even when γ reached 200, with an average of 11.3 solver iterations. The hybrid Newton's and Brent's methods were also robust and reached γ = 200 with an average of 5.6 and 13.0 solver iterations, respectively. γ = 200 implied the maximum radius could be 200 times larger than the minimum in a single ellipsoid, and thus it was sufficient for physics-based simulation with ellipsoids. The number of solver iterations was almost insensitive to Γ in contrast to γ. Figure 4 shows the maximum and average number of solver iterations required to compute the closest approach distances for each of the 1 million pairs of ellipsoids generated randomly, with Γ increasing from 1 to 200 and γ fixed at 3. We can observe that the computation time was almost insensitive to Γ, the proportion between the gross sizes of the ellipsoids. Consequently, the proposed methods could be effectively used for simulating ellipsoids with various sizes. The next experiment was conducted to test the number of solver iterations with respect to the error tolerance. Figure 5 shows the average number of solver iterations required to compute the closest approach distances for 1 million pairs of random ellipsoids with γ = 3 (solid lines) and γ = 6 (dashed lines) when u decreases from 1 to 10 −8 . Γ was fixed at 3. The hybrid Newton's and Brent's methods exhibited quadratic convergence, whereas the hybrid fixed-point iteration method exhibited linear convergence. However, when γ was small and the error tolerance was large, the hybrid fixed-point iteration method performed better than the others. This observation can be effectively exploited with the actual error tolerance given in Equation (14) as illustrated in the final experiment. The final experiment demonstrated the effectiveness of the proposed methods in real-time as-rigid-as-possible dynamic simulation of deformable bodies approximated with ellipsoids [3]. Figure 6 shows the simulation result of 180 deformable bodies approximated with 4404 ellipsoids. A spatial subdivision technique [15] was employed to reduce the number of collision tests between a pair of ellipsoids, and 49,716,944 collision tests were performed during 60 s of simulation. The ratios γ and Γ between radii were 4.86 and 2.55, respectively. Table 1 lists the average and maximum number of solver iterations and the average computation time required to satisfy the stopping criterion given in Equation (13) with u = 10 −8 . The computation time was measured in two different manners that exploited (1) a single core and (2) all 18 cores with a simple parallelization using OpenMP. In both cases, the hybrid Newton's method was the most efficient. In real-time applications such as computer games, computational efficiency has higher priority over simulation accuracy. Moreover, the interference between ellipsoids was scarcely noticeable even when the interference was 1% of the minimum radius. Thus, the actual error tolerance given in Equation (14) was adequate as a stopping criterion. Table 1 lists the average and maximum number of solver iterations and the average computation time when x = 10 −2 . With the actual error tolerance, the hybrid fixed-point iteration method was shown to be the most efficient. From this experiment, we can conclude that the hybrid Newton's method is a good choice when the accuracy is important, and the hybrid fixed-point iteration method is a good choice in real-time applications.

Conclusions
The computation of the closest approach distance of two ellipsoids in their inter-center direction is crucial for collision handling among ellipsoids that approximate rigid and deformable bodies in physics-based dynamics simulation [1][2][3] and also plays important roles in the simulation of liquid crystals and colloidal systems [8][9][10][11][12]. We proposed two intuitive and efficient methods to compute the closest approach distance of two ellipsoids. Based on the intuitive approach introduced in position-based dynamics with ellipsoids [1], we formulated a set of equations for two ellipsoids contacting each other externally with the inter-center distance, contact point, and normal vector. The equations can be solved accurately and efficiently using a hybrid of Newton's method and bisection method with root bracketing. In addition, we introduced a novel criterion expressed in terms of the error in distance. Our experimental results demonstrate that this criterion can be effectively employed in real-time applications such as computer games by allowing an unnoticeable error with a hybrid of the fixed-point iteration method and bisection method. Currently, our methods deal with only static ellipsoids. We plan to extend our methods to cope with moving ellipsoids.