# Minimum Distance between a Line and a Circle in 3D

Initializing live version

Requires a Wolfram Notebook System

Interact on desktop, mobile and cloud with the free Wolfram Player or other Wolfram Language products.

This Demonstration shows how to compute the minimum distance between a line and a circle in 3D and draws the line segment joining the minimizing points. You can move the origin of the line and control the line's orientation. Some configurations yield two solutions. If the line is orthogonal to the circle and passes through the circle center, then every point on the circle is equidistant from the line; in this case, "equal distance = True" and one point is chosen and drawn. Additionally, you can construct a torus around the circle with a tube radius of half the minimum distance using the "tube and torus opacity" slider.

Contributed by Aaron T. Becker, Victor M. Baez and Nikhil Navkar (August 27)
Open content licensed under CC BY-NC-SA

## Details

The code in this Demonstration was transcribed to Wolfram Language from the C++ line-circle distance algorithm by David Eberly [2]. The line is defined by a direction vector and an origin coordinate . The circle is defined by its center coordinate , its radius and the normal of its plane n. A distance function between points on the parameterized line and the closest point on the circle is formed and minimized. Minimizing this function involves solving for the roots of a polynomial of degree four. Additional functions with simpler arithmetic are called for special cases, such as when the line is parallel to the plane of the circle (and more; see [1]).

The full derivation and detailed explanation can be found in [1].

Use the sliders to change the configuration of the line and the circle:

is the orientation of the line,

is the orientation of the circle,

is the latitude and

is the longitude.

The coordinates of the line origin and the line's orientation vector are shown in dark red. The coordinates of the circle's center and its orientation vector are shown in dark blue. The pair of points and that yield the shortest distance and the line segment joining them are in green. The "tube and torus opacity" slider reveals a torus around the circle and a tube around the line, each with a tube-radius of half the minimum distance.

Special cases arise when the line is parallel to the circle plane (see Snapshot 1) or passes through the circle center (see Snapshot 3). In these cases there are two solutions.

References

[1] D. Eberly. "Distance to Circles in 3D." Geometric Tools. (Jun 14, 2023) www.geometrictools.com/Documentation/DistanceToCircle3.pdf.

[2] D. Eberly. "DistLine3Circle3.h." Geometric Tools. (Jun 14, 2023) www.geometrictools.com/GTE/Mathematics/DistLine3Circle3.h.

## Permanent Citation

Aaron T. Becker, Victor M. Baez and Nikhil Navkar

 Feedback (field required) Email (field required) Name Occupation Organization Note: Your message & contact information may be shared with the author of any specific Demonstration for which you give feedback. Send