The lowest distance of two points on two curves
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Risposte (1)
John D'Errico
il 12 Gen 2022
Modificato: John D'Errico
il 12 Gen 2022
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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!