how to get x and y components of normal vector of curve like this??
Show older comments
I am trying to get the x and y components of the normal vector in the curve similar to the one attached here, any idea how to implement this ??
Answers (1)
Satwik
on 24 Apr 2025
I understand that the goal is to compute the the X and Y components of the normal vector to a given curve. This can be achieved by following the steps given below:
- Parameterize the curve as ( (x(t), y(t)) ) or as discrete points ((x_i, y_i)).
- Compute the tangent vector at each point.
- Find the normal vector by rotating the tangent vector by 90°.
Here is an exmaple script you may refer to implement the above steps:
x = linspace(-2, 2, 100);
y = x.^2; % Example: parabola
dy_dx = gradient(y, x); % Numerical derivative
% Tangent vector: (1, dy_dx)
% Normal vector: (-dy_dx, 1)
norms = sqrt(dy_dx.^2 + 1);
nx = -dy_dx ./ norms;
ny = 1 ./ norms;
figure;
plot(x, y, 'b-', 'LineWidth', 2); hold on;
quiver(x, y, nx, ny, 0.3, 'r');
axis equal; grid on;
title('Parabola with normal vectors');
legend('Curve', 'Normals');
Here is an image of the resulting plot:

I hope this helps!
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!