问题
I have a curve and I want to find the normal vector at a given point on this curve, later I have to find the dot product of this normal vector with another vector.
I tried the gradient function of MatLab, but I guess it doesnt work when we need to find the gradient at a specific point still I am not sure if I am wrong.
Please guide me how can I achieve this in MatLab.
Thanks in advance.
回答1:
Using the explanation from this incredible SO question:
if we define dx=x2-x1 and dy=y2-y1, then the normals are (-dy, dx) and (dy, -dx).
Here's an example using an analytic curve of y = x^2
x = 0:0.1:1;
y = x.*x;
dy = gradient(y);
dx = gradient(x);
quiver(x,y,-dy,dx)
hold on; plot( x, y)
which gives:
PS: Sorry about the tangential example!!! Got in a hurry. Thanks to Schorsch and Shawn314!
回答2:
I hate to say it, but going back to Calculus 1 might be a pretty viable option here. Calculate derivative of curve at your point, find normal to that, I think if you were to just google "Matlab deriviate" and "calculate normal to derivative" you should be good
来源:https://stackoverflow.com/questions/17324936/how-to-find-the-normal-vector-at-a-point-on-a-curve-in-matlab