The lowest distance of two points on two curves
1 view (last 30 days)
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.
John D'Errico on 12 Jan 2022
Edited: John D'Errico on 12 Jan 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];
IDX = knnsearch(XYZ1,XYZ2);
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.