- 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?

13 views (last 30 days)

Show older comments

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

Robert U
on 16 Mar 2022

If it is just about the total length travelled, I do not think there is a need for generalization. You can assume that the way travelled between coordinates is piecewise linear and add all the linear way elements.

If in any case that would be an estimation that is too rough, you can choose other trajectory assumptions ending up in polynomials that must be described by transition conditions for smooth curves (i doubt that is really necessary) and add a lot of complexity to the trajectory that usually does not lead to a much improved accuracy.

BTW: You did not answer any other question concerning the task you would like to tackle.

Kind regards,

Robert

### Answers (1)

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 .

##### 8 Comments

Sam Chak
on 19 Mar 2022

Nothing works without steadfastness in pursuing what you desire. Kudos to you!

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!