Lateral Deviation Between two curves

How can the lateral deviation be calculated and drawn between two curves? For instance i have two paths; a desired path and a driven path. I would like to find the lateral deviation or error from the driven path to the desired path and also display the error as a connecting line. Apparently theres a way to do this that uses the normal to the tangent at each point of the driven line, however, i cant quite forget out how to go about that information.
close all; clear all; clc;
for i = 1:100
x(i) = i;
desired_path(i) = 10+x(i).^2;
driven_path(i) = .5*x(i).^2;
end
figure
hold on
plot(x(:), desired_path(:));
grid on;
plot(x(:), driven_path(:));
legend('Desired Path', 'Driven Path')
hold off;

1 Comment

You mean a plot of abs(f^(-1)(y) - g^(-1)(y)) over y if f(x) = desired path and g(x) = driven path ?

Sign in to comment.

Answers (2)

desired_path_invers = @(y)sqrt(y-10);
true_path_invers = @(y)sqrt(2*y);
y = 10:0.1:12000;
plot(y,abs(desired_path_invers(y)-true_path_invers(y)))

1 Comment

Thank you for your response, however, what i am looking to achieve is better represented by the picture attached below. Each arrow represents the lateral error between the two paths where the arrows are normal to the driven path and passes through the closest point on the desired path along the normal line. I would like to display the lateral error between the two lines as a seperate line. in addition, i would like to plot the lateral error seperately.
close all; clear all; clc;
for i = 1:10
x(i) = i;
y1(i) = 10+x(i)^2;
y2(i) = .5*x(i)^2;
end
figure
hold on
plot(x(:), y1(:));
grid on;
plot(x(:), y2(:));
legend('Desired Path', 'Driven Path')
hold off;

Sign in to comment.

The normal to "driven_path" and the "desired_path" do not cross for r(4) < x < r(2). That's why there is a gap in the distance graph.
syms x t
driven_path = 0.5*x^2;
desired_path = t^2 + 10;
normal_to_driven_path = 0.5*x^2 - 1/x*(t-x);
T = solve(normal_to_driven_path == desired_path,t)
T = 
p = [2 0 -36 0 1];
r = roots(p)
r = 4×1
-4.2394 4.2394 -0.1668 0.1668
cutpoint1 = subs(desired_path,t,T(1))
cutpoint1 = 
cutpoint2 = subs(desired_path,t,T(2))
cutpoint2 = 
dist1 = norm(-[x,driven_path]+[T(1),cutpoint1]);
dist2 = norm(-[x,driven_path]+[T(2),cutpoint2]);
dist1 = matlabFunction(dist1);
dist2 = matlabFunction(dist2);
x1 = 1e-8:0.0001:r(4);
x2 = r(2):0.001:15;
x3 = r(3):0.0001:-1e-8;
x4 = -15:0.001:r(1);
plot(x1,dist1(x1),'r',x2,dist1(x2),'r',x3,dist1(x3),'r',x4,dist1(x4),'r')

Categories

Asked:

on 28 Oct 2022

Edited:

on 30 Oct 2022

Community Treasure Hunt

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

Start Hunting!