Matlab 版 (精华区)
发信人: Mathsims (第二百三十七世剩闲), 信区: Matlab
标 题: 一个画二维箭头的程序
发信站: 哈工大紫丁香 (Wed Dec 10 19:24:51 2003), 站内信件
写来自己用的。放上来是想让大家挑挑毛病。
function arrow = Arrow2D(x0,y0,x1,y1,Color,Width)
%Arrow2D draw a two-dimension arrow by using the MATLAB patch function.
%
% Arrow2D displays this information.
%
% Arrow2D(x0,y0,x1,y1) draws a two-dimension arrow, which head at point
% (x1,y1), tail at point (x0,y0), and using default color and line width.
% the four input arguments must be numbers.
%
% Arrow2D(x0,y0,x1,y1,Color) draws a two-dimension arrow, which head at
% point (x1,y1), tail at point (x0,y0), and sets its color with Color.
% Color can be a 1-by-3 vector or a single ColorSpec.
%
% Arrow2D(x0,y0,x1,y1,Color,Width) draws a two-dimension arrow, which head a
t
% point (x1,y1), tail at point (x0,y0), and sets its color with Color and li
ne
% width with Width. Width must be a number.
%
% NOTE: If you want a better effect, please set your axis square.
%
% EXAMPLE:
% Arrow2D(1,1,0,0);
% Arrow2D(-1,-1,0,0);
% Arrow2D(-1,1,0,0);
% Arrow2D(1,-1,0,0);
% axis square
% Mathsims 12-10-2003
% version: 3
ni = nargin;
if ni == 0,
help Arrow2D;
return;
elseif ni < 4,
error('Too fewer input argument!');
elseif ni == 4,
Color = 'k';
Width = 0.01;
elseif ni == 5,
Width = 0.01;
else
error('Too many input argument!')
end
warning off % not display the "divide by zero" warning
theta = atan((y1-y0)/(x1-x0));
if x1 > x0,
Y = y1 - 6*Width*sin(theta);
X = x1 - 6*Width*cos(theta);
else
Y = y1 + 6*Width*sin(theta);
X = x1 + 6*Width*cos(theta);
end
deltaX = 1.5*Width*sin(theta);
deltaY = 1.5*Width*cos(theta);
xx = [x1, X+deltaX;...
X+deltaX, X+deltaX/3;...
X+deltaX/3, x0+deltaX/3;...
x0+deltaX/3, x0-deltaX/3;...
x0-deltaX/3, X-deltaX/3;...
X-deltaX/3, X-deltaX;...
X-deltaX, x1];
yy = [y1, Y-deltaY;...
Y-deltaY, Y-deltaY/3;...
Y-deltaY/3, y0-deltaY/3;...
y0-deltaY/3, y0+deltaY/3;...
y0+deltaY/3, Y+deltaY/3;...
Y+deltaY/3, Y+deltaY;...
Y+deltaY, y1];
arrow = patch(xx,yy,Color,'EdgeColor',Color); % draw the arrow.
--
不是什么高山,
也不是什么星斗,
我只是一块有信念的石头。
小样儿,敢惹我,看我砸不死你!
※ 来源:.哈工大紫丁香 bbs.hit.edu.cn [FROM: 202.118.226.28]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.034毫秒