How do I get distance between two curves that cannot be described with a polynomial?

21 views (last 30 days)
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.
  6 Comments
Jacinth Gudetti
Jacinth Gudetti on 17 Mar 2022
Edited: Jacinth Gudetti on 17 Mar 2022
@Sam Chak @Robert U @John D'Errico I have taken some more time to analyze my problem and I believe time should not be considered. rather I think it should be a function of perpendicular distance from the planned (red) path to the actual (blue) path. Time may in fact complicate matters even further as what I am looking for is for the algorithm's accuracy to stay close to the red line rather than anything with respect to time.

Sign in to comment.

Answers (1)

Sam Chak
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)
hold on
% 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)
hold off
Results:
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.
  8 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!