The lowest distance of two points on two curves

조회 수: 1 (최근 30일)
Dominik Cech
Dominik Cech 2022년 1월 12일
편집: John D'Errico 2022년 1월 12일
Hello,
I have two curves. Each is made of 100 points with X, Y and Z coordination. How do I find for each point on one curve point on the second one which has smallest distance betwen them? Someone told I have to brute force it but I realy dont know how to do it.
  댓글 수: 1
Torsten
Torsten 2022년 1월 12일
편집: Torsten 2022년 1월 12일
Take the first point on curve 1, calculate the distance to each of the 100 points on the other curve and take the minimum of these distances.
Proceed with the second point on curve 1.

댓글을 달려면 로그인하십시오.

답변 (1개)

John D'Errico
John D'Errico 2022년 1월 12일
편집: John D'Errico 2022년 1월 12일
PDIST, from the stats toolbox can compute the set of all interpoint distances between two sets of data. Then you could just take the smallest distance for each point on curve 1.
You can also use my IPDM, as found on the file exchange. But by far the best is to use KNNSEARCH. For example...
t = linspace(0,1)';
XYZ1 = [sin(t),cos(t),sin(2*t)];
XYZ2 = [t,t.^2,t.^3];
plot3(XYZ1(:,1),XYZ1(:,2),XYZ1(:,3),'r-')
hold on
plot3(XYZ2(:,1),XYZ2(:,2),XYZ2(:,3),'g-')
grid on
box on
IDX = knnsearch(XYZ1,XYZ2);
plot3([XYZ1(:,1)';XYZ2(IDX,1)'],[XYZ1(:,2)';XYZ2(IDX,2)'],[XYZ1(:,3)';XYZ2(IDX,3)'],'b-')
So every blue line connected a point on the red curve to its closest cousin on the green curve. (Note that the closest point on the red curve, for any point on the green curve is a not a symmetric thing.)
Do any of these solutions find the closest point on the CURVE? NO!!!!!!! All you have are isolated points along a curve, not the curve itself. I do have a tool on the file exchange that does solve that problem, by finding the closest point on a spline interpolant of your curve. That is the distance2curve function. knnsearch should be adequate though.

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by