# shortest distance between two circles in 3D

Returns the shortest distance between two circles in 3D, the pair(s) of closest points, and if the circles are equidistant.
Updated 26 Apr 2023

• distanceCircleCircle3D.m Computes the shortest distances in 3D between two circles by solving an 8th order polynomial (after checking for special cases).
• fminconDistanceCircleCircle3D.m performs the same task numerically, but is slower, only returns one solution, doesn't always find the optimum, and requires the Optimization toolbox.
• testdistanceCircleCircle3D.m draws the circles and their minimum non-intersection tori. It also draws the special cases in 2D and many interesting cases in 3D.
• compareAccuracyCircleCircle3D.m generates nSamples random circles and compares the accuracy and performance of distanceCircleCircle3D and fminConDistanceCircleCircle3D
distanceCircleCircle3D(N0, r0, C0, N1, r1, C1)
Inputs: two circles circle 0, and circle 1, each described by 3 parameters.
1. N0: circle 0 normal vector (3x1)
3. C0: circle 0 center position (3x1)
4. N1: circle 1 normal vector (3x1)
6. C1: circle 1 center position (3x1)
If no inputs are given, two random circles in 3D are generated.
Outputs:
result, a struct that includes the elements:
1. distance: shortest distance (scalar)
2. sqrDistance: squared shortest distance (scalar)
3. numClosestPairs: how many closest pairs on the circles exist ,
4. circle0Closest: coordinates of closest point on circle 0, 3xnumClosestPairs
5. circle1Closest: coordinates of closest point on circle 1, 3xnumClosestPairs
6. equidistant: if infinite solutions exist
Transcribed from C++ to Matlab by Aaron Becker atbecker@uh.edu, and Victor Montano, based on the 3D circle-circle distance algorithm described in https://www.geometrictools.com/Documentation/DistanceToCircle3.pdf and available at https://www.geometrictools.com/GTE/Mathematics/DistCircle3Circle3.h
The notation used in the code matches that of the document.
David Eberly, Geometric Tools, Redmond WA 98052
Version: 6.0.2022.01.06

### Cite As

Aaron T. Becker's Robot Swarm Lab (2024). shortest distance between two circles in 3D (https://www.mathworks.com/matlabcentral/fileexchange/128183-shortest-distance-between-two-circles-in-3d), MATLAB Central File Exchange. Retrieved .

##### MATLAB Release Compatibility
Created with R2023a
Compatible with any release
##### Platform Compatibility
Windows macOS Linux

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.2