How to find the normal vector at a point on a curve in MatLab

16,342

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:

Quiver

PS: Sorry about the tangential example!!! Got in a hurry. Thanks to Schorsch and Shawn314!

Share:
16,342

Related videos on Youtube

Sagar
Author by

Sagar

Updated on June 04, 2022

Comments

  • Sagar
    Sagar almost 2 years

    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.

  • Schorsch
    Schorsch almost 11 years
    Aren't these tangential vectors and not normal vectors?
  • Shaun314
    Shaun314 almost 11 years
    My thoughts exactly Schorsch
  • Sagar
    Sagar almost 11 years
    Thanks for your suggestion but for any1 that would be the first option to try. Nevertheless, it is not what I want. anyways thanks!
  • Shaun314
    Shaun314 almost 11 years
    Yeah, it looks like the other answer was really good, and I know there are a lot of FEX entries as well which I think calculate it for 2-d and 3-d curves so those might be worth checking out as well, best of luck!