Determine the distance between two ellipses (in 3D)

版本 1.3 (9.2 KB) 作者: Rody Oldenhuis
Determine the minimum distance (and corresponding angles) between two ellipses
1.1K 次下载
更新时间 2020/5/2

The problem of finding the geometric (minimum) distance between two arbitrary ellipses is surprisingly difficult. The general problem of finding all stationary points (minimum/maximum/saddle, no less than 12 possible points) has indeed been solved, but that algorithm is horrificly complex and would require thousands if not millions of operations once implemented.
The function distanceEllipseEllipse() is based on a somewhat more practical algorithm which limits itself to minima in the distance function. It is based on repeatedly finding the distance between a point and an ellipse, which can be done analytically (see my other post, distanceEllipsePoints.m). The algorithm by itself is not very robust (it frequently finds a local minimum, which is *not* the true distance).
This function executes the algorithm 4 times, for 4 different initial values, which greatly improves its robustness. Some numerical experimentation (comparing with a brute-force search) has shown that the true minimum distance is returned in more than 95% of the cases. The algorithm is implemented such that MATLAB's JIT-accelerator can accelerate it to the fullest extent, which makes it pretty fast and well-suited to handle large datasets requiring this calculation.
This is an implementation of the algorithm described in
Ik-Sung Kim: "An algorithm for finding the distance between two
% ellipses". Commun. Korean Math. Soc. 21 (2006), No.3, pp.559-567.

A copy-pastable example (also in header of M-file):

% Ellipse1 Ellipse2(=circle)
a = [2.0 1.0];
b = [0.5 1.0];
c = {[0,0,0], [-2,2,0]}; % location of centers
u = {[1,0,0], [1,0,0]}; % both oriented in XY-plane
v = {[0,1,0], [0,1,0]}; % to visualize them more easily

% plot the ellipses
f = 0:0.01:2*pi;
E1 = [a(1)*cos(f) + c{1}(1); b(1)*sin(f) + c{1}(2)];
E2 = [a(2)*cos(f) + c{2}(1); b(2)*sin(f) + c{2}(2)];
figure, hold on
plot(E1(1,:),E1(2,:),'r', E2(1,:),E2(2,:),'b')
axis equal

% run routine
[min_dist, fp_min, fs_min] = ...
distanceEllipseEllipse(a,b,c,u,v)

% plot the minimum distance returned
x = [a(1)*cos(fp_min) + c{1}(1), a(2)*cos(fs_min) + c{2}(1)];
y = [b(1)*sin(fp_min) + c{1}(2), b(2)*sin(fs_min) + c{2}(2)];
line(x,y,'color', 'k')

This should generate the screen shot given here.

引用格式

Rody Oldenhuis (2024). Determine the distance between two ellipses (in 3D) (https://github.com/rodyo/FEX-distanceEllipseEllipse/releases/tag/v1.3), GitHub. 检索来源 .

MATLAB 版本兼容性
创建方式 R2009b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Geometric Transformation and Image Registration 的更多信息

Community Treasure Hunt

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

Start Hunting!

无法下载基于 GitHub 默认分支的版本

版本 已发布 发行说明
1.3

See release notes for this release on GitHub: https://github.com/rodyo/FEX-distanceEllipseEllipse/releases/tag/v1.3

1.2.0.0

[linked to Github]
Description update

1.1.0.0

Updated contact info

1.0.0.0

要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库
要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库