%Example data
x=0:0.1:10;
y = 0.230 + -0.046*x + -0.208*x.^2 ;
plot(x,y);
%Find the tangent and normals at all points
dy = [0 diff(y)./diff(x)];
py = -1./dy;
%Choose a point
n = 60;
X = x(n);
Y = y(n);
hold on
plot(X, Y, 'or')
%Find the equation of the straight line normal to that point. You can do this in one step (yn = py(n)*(x - X) + Y) but I've done it in two to illustrate where this comes from
c = Y - py(n)*X;
yn = py(n)*x + c;
plot(x, yn, 'g')
how to calculate equation to a perpendicular to polynomial line
-
26-06-2022 - |
문제
I have a polynomial y = 0.230 + -0.046*x + -0.208*x^2
.
I want to calculate the perpendicular to this line cutting another line at (X,Y).
해결책 2
다른 팁
An alternative is to compute the analytical result which is not terribly difficult. (you could use the symbolic toolbox for that but the NN sitting on your head will do):
%Example data
x=0:0.1:10;
y = 0.230 + -0.046*x + -0.208*x.^2 ;
plot(x,y);
%Find the tangent and normals at all points (*edited*)
slope = (-0.046 + -2*0.208*x);
py = -1./slope; % <-- modified from Dan's expression
% to use analytical derivative
%Choose a point
n = 60;
X = x(n);
Y = y(n);
hold on
plot(X, Y, 'or')
% Copying @Dan: Find the equation of the straight line normal to that point. You can do this in one step (yn = py(n)*(x - X) + Y) but I've done it in two to illustrate where this comes from
c = Y - py(n)*X;
yn = py(n)*x + c;
plot(x, yn, 'g')
axis tight equal
Using axis equal
is also a good idea in this example to see that you really have orthogonal curves.
제휴하지 않습니다 StackOverflow