- Residual distance - think of the path as e.g. traveled distance over time; at each time instant or traveled distance point the Euclidian distance between the two trajectories could be measured.
- Local distance - for each point of a reference path (choose one of the trajectories as reference) the minimum distance to the second path can be calculated
- Overal distance difference - for each point measured the overall travelled distance can be compared
How do I get distance between two curves that cannot be described with a polynomial?
21 views (last 30 days)
Show older comments
Jacinth Gudetti on 15 Mar 2022
Commented: Sam Chak on 19 Mar 2022
Hi guys so I have a unique problem. I'm comparing the distance between two path planning algorithms and these are the results I get in the MATLAB figure. I want to compare the distance between the two paths and output a single graph that has the offset of the distance between the curves, but as you can see, I cannot really use fit with smoothingspline ("fit(X,Y,"smoothingspline")") because both plots cannot be described in a single equation, trust me, I have tried.
I also tried using movmean to average the functions but that made the two graphs fall apart even further sicne the X and Y values don't exactly line up. I figure I will need to use a 3rd dimension like time to orient it but I would like to avoid doing that. My last resort could be running computer vision to get a white space between the two and grab the area between them but that is not a very exact analysis.
Sam Chak on 15 Mar 2022
Edited: Sam Chak on 15 Mar 2022
Here is an example. Say, there are two paths: one is an onion-shaped path and the other is a circular path.
The onion-shaped path with a center at (, ) can be described with
, and ,
while the cicular path with a radius r and the same center is given by
, and .
t = 0:pi/50:2*pi;
r = 1;
xc = 2;
yc = 3;
% Onion-shaped path
x1 = r*(cos(t)).^3 + xc;
y1 = r*sin(t) + yc;
h1 = plot(x1, y1, xc, yc, 'o');
daspect([1, 1, 1])
f1 = @(t) sqrt((-3*((cos(t)).^2).*sin(t)).^2 + cos(t).^2);
len1 = integral(f1, 0, 2*pi)
% Circular path
x2 = r*cos(t) + xc;
y2 = r*sin(t) + yc;
h2 = plot(x2, y2, xc, yc, 'o');
daspect([1, 1, 1])
f2 = @(t) sqrt(sin(t).^2 + cos(t).^2);
len2 = integral(f2, 0, 2*pi)
len1 = 5.8290
len2 = 6.2832
The onion-shaped path is shorter than the circular path. You can also verify that circumference for the circle is .
Also check out @John D'Errico's amazing works on the File Exchange.
Sam Chak on 19 Mar 2022
Find more on Directed Graphs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!