matlab

normal vector(법선 벡터) 그리기 (구버전)

humming_stereo 2022. 12. 23. 16:36
% o : original vector
% b : base line
% n : nomal line
% theta : between angle
 
clc; clear; close all;
 
%% original line (input set)
% original vector set
o.x = [-1 2];
o.y = [1 -2];
o.u = [3 2];
o.v = [-1 -4];
o.a = atan2d(o.u,o.v);
o.mag = sqrt(o.u.^2+o.v.^2);
 
% tracking line set
b.u = -5;
b.v = 5;
b.a = atan2d(b.v,b.u);
 
 
%% nomal line
if b.a > 0
n.a = b.a-90;
else
n.a = b.a+90;
end
 
% angle between
theta = (n.a-o.a);
 
n.mag = o.mag.*cosd(theta);
n.u = n.mag.*sind(n.a);
n.v = n.mag*cosd(n.a);
 
 
%% figure
figure('visible','on')
set(gca,'fontname','Arial','fontweight','bold','fontsize',15,'Box','on');
set(gcf,'color','w','Units','Normalized','OuterPosition',[1.2 0.2 .3 .5]);
hold on;
 
% plot
plot([-10*cosd(90-b.a) 10*cosd(90-b.a)],[-10*sind(90-b.a) 10*sind(90-b.a)],'k')
quiver(o.x,o.y,n.v,n.u)