# How to define a path from a set of x-y points and estimate its smoothness?

4 views (last 30 days)
Luigi Truppa on 29 Sep 2021
Commented: William Rose on 29 Sep 2021
Hi to everyone,
I have a set of x-y points that define a path in a XY graph. How can I estimate the smoothness of the path?
I know that in Matlab there is a function called "smoothness" that does what I want but the input is a "path object", which I do not fully understand. So, the question I made before could also be rewritten as: "Can I obtain a path object from a set of x-y points?".

William Rose on 29 Sep 2021
Edited: William Rose on 29 Sep 2021
Example with two paths, each with 51 waypoints. Path A is a sequence of random points. Path B is a circle.
It seems that path objects must be in three dimensions, so I have added a third dimension, which is zero for all points. You also need to define a space containing the path. This space should be larger than the path, to avoid bumping into the edges. I suspect the extra margin should be at least the minimum turning radius, whose default value is 1.
N=21; %number of waypoints
A=[2*rand(N,2)-1,zeros(N,1)]; %path of random points
B=[cos(0:2*pi/(N-1):2*pi)',sin(0:2*pi/(N-1):2*pi)',zeros(N,1)]; %unit circle path
figure;
plot(A(:,1),A(:,2),'r.-',B(:,1),B(:,2),'b.-'); %plot waypoints
legend('Waypoints A','Waypoints B');
axis equal;
dubinsSpace=stateSpaceDubins([-2 2; -2 2; -1 1]); %define a space for the paths
pathobjA=navPath(dubinsSpace); %create a path object
pathobjB=navPath(dubinsSpace); %create a path object
append(pathobjA,A); %add waypoints to path object A
append(pathobjB,B); %add waypoints to path object B
pathMetricsObjA=pathmetrics(pathobjA); %compute path metrics for path A
pathMetricsObjB=pathmetrics(pathobjB); %compute path metrics for path B
smA=smoothness(pathMetricsObjA);
smB=smoothness(pathMetricsObjB);
fprintf('Smoothness of path A=%.3f, path B=%.3f\n',smA,smB);
Smoothness of path A=1.918, path B=1.936
Run the code above. Results differ for each run, due to the random numbers. The help for smoothness says "Values close to 0 indicate a smoother path. Straight-line paths return a value of 0.". Therefore the reults above indicate that path A is smoother than path B. That is clearly contrary to our concept of smoothness. Therefore I would not use this smoothness estimate. I would google to see what other estimates exist. I would consider making my own. It might involve the average value of the third derivative ("jerk").
Experiment with how changing the minimum turning radius alters the result. See if interpolating more points changes the smoothness.
Good luck!
William Rose on 29 Sep 2021
Determine the desired properties of your smoothness estimate. Do you want a circle and a straight line to have equal or different smoothnesses? It seems to me that a circle with many points is smooth, but a circle with just a few points (such as a square or equilateral triangle) is not smooth.