Minimum distance between a disk and a circle in 3D: pair of closest points? Let a disk $D$ in $\mathbb{R}^3$ be given by a center $O_d$, a radius $R_d > 0$, and a unit normal vector $N_d$ to the plane $\{X \in \mathbb{R}^3 \mid N_d \cdot (X-O_d) = 0\}$ containing the disk. Let a circle $C$ in $\mathbb{R}^3$ be given by a center $O_c$, a radius $R_c > 0$, and a unit normal vector $N_c$ to the plane $\{X \in \mathbb{R}^3 \mid N_c \cdot (X - O_c) = 0\}$ containing the circle.
What is an algorithm to obtain a pair of points $(P_d, P_c) \in D \times C$ of minimal Euclidean distance?

My first attempt would be to choose coordinates $(x,y,z)$ such that the disk is in the $xy$-plane centered at the origin, looking at the points of the circle with minimum/maximum $z$-values, and computing their distance to the disk. That doesn't always suffice though, e.g. if both $z$-values are positive and the projection to the $xy$-plane of the point with maximum $z$-value is inside the disk and the projection to the $xy$-plane of the point with minimum $z$-value is outside the disk. I could also make use of the closest points between two circles, known e.g. from Fast and Accurate Circle-Circle and Circle-Line 3D Distance Computation by D. Vranek (2002). Does the combination of those two methods cover all the cases?
 A: You can use the minimum of the circle-to-circle distance and the circle-to-plane distance, provided that you delimit the circle to the inside of the cylindre based on the disk. (You will have to compute the intersection of the orthogonal projection of the circle - an ellipse - with the disk, in 2D.)


WLOG, let the disk be centered at the origin and lying on the plane $XY$. It vector equation can be written
$$\vec p=\vec c+\vec u\cos\theta+\vec v\sin\theta.$$
The point closest to $XY$ is the one that minimizes
$$p_z=c_z+u_z\cos\theta+v_z\sin\theta.$$
It is an easy matter to check if it projects inside the disk.
The endpoints of the arc(s) of circle inside the cylindre are found by solving the inequation
$$(\vec c_{xy}+\vec u_{xy}\cos\theta+\vec v_{xy}\sin\theta)^2\le R^2.$$
Expanding, you get a quadratic trigonometric inequation. By means of the Weiertrass substitution, you turn it to a quartic inequation, which is solvable analytically (this complexity is unavoidable). After resolution, you get zero, two or four endpoints and keep the lowest.
