📄 arrow3.m
字号:
function arrow3(point1,point2,S,rlength,rwidth)
% The function:
%
% arrow(point1,point2,S,rlength,rwidth)
%
% draws an arrow from point <point1> to point <point2>
% in the 3-dimensional space.
% Optional arg <S> is like in plot3(X,Y,Z,S);
% default value is '-'.
% Optional arg <rlength> is the relative length of the
% pointing end; default value is 0.3.
% Optional arg <rwidth> is the relative width of the
% pointing end; default value is 0.2.
% args
if nargin<2, error('not enough args'); end;
if nargin<3, S = '-'; end;
if nargin<4, rlength = 0.3; end;
if nargin<5, rwidth = 0.2; end;
% base arrow
arrowx = [0,1,1.0-rlength,1,1.0-rlength];
arrowy = [0,0,+0.5*rwidth,0,-0.5*rwidth];
arrowz = [0,0, 0,0, 0];
% vector
v = point2 - point1;
if length(v)==3,
if size(v,2)==3, v = v'; end;
end;
% dilation, rotation & plot
if length(v)==3,
n = norm([v(2),v(3)]);
if n==0,
% not rot needed
arrowxyz = v(1) * [arrowx;arrowy;arrowz];
else,
% rot around x axis
drot23 = [[ 1, 0, 0];
[ 0,+v(3)/n,-v(2)/n];
[ 0,+v(2)/n,+v(3)/n]];
v = drot23*v;
% norm of rotated vector
n = norm([v(1),v(3)]);
% rot around y axis
drot13 = [[+v(1)/n, 0,+v(3)/n];
[ 0, 1, 0];
[-v(3)/n, 0,+v(1)/n]];
v = drot13*v;
arrowxyz = norm(point2-point1)*drot23'*drot13'*[arrowx;arrowy;arrowz];
end;
plot3(point1(1)+arrowxyz(1,:),point1(2)+arrowxyz(2,:),point1(3)+arrowxyz(3,:),S);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -