Unit normal vector to curve
Sometime we need to draw normal to curve, so we need to remember math from school…
i decided to write small Matlab program to implement this.
The Program
figure,imshow(ones(400));
x =[ 229.0000
253.0000
242.0000
231.0000
154.0000
105.0000
69.0000
66.0000
77.0000
138.0000];
y =[ 283.0000
269.0000
222.0000
204.0000
185.0000
167.0000
130.0000
80.0000
45.0000
27.0000];
hold on;
plot(x,y,’r’)
plot(x,y,’ro’)
for(k=2:length(x)-1)
plot(x(k),y(k),’bo’)
%% step 1 dv/dt
dx = (x(k+1)-x(k-1));
dy =(y(k+1)-y(k-1));
dvdt = [dx;dy];
%% step2 rotate 90%
dvdtRot = [-dy ;dx];
%% Step 3: Scale it to magnitude 1
% unit vector
% sqrt(0.2818*0.2818 + -0.9595*(-0.9595))=1
dvdtRotNorm = dvdtRot/norm(dvdtRot);
scale=50;
pNorm = [x(k);y(k)]+scale*dvdtRotNorm;
plot(pNorm(1),pNorm(2),’gs’)
line([x(k);pNorm(1)],[y(k);pNorm(2)])
end