搜档网
当前位置:搜档网 › MATLAB画箭头

MATLAB画箭头

MATLAB画箭头
MATLAB画箭头

%网上下载到一些MATLAB画有向线段的函数,由于不能有效地满足在图像上画有限线段,于是自己动手写了一个,希望对你有用%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %函数的功能是画箭头

%注意事项:

%line函数的用法

%example

%Img=imread('Lena.bmp');

%p=[100 200];

%v=[100 50] ;

% figure(1)

%imshow(Img);

%hold on;

%m_arrow(p,v,'r'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function m_arrow(PointStart,PointEnd,color)

if nargin < 3

color = 'b';

end

m = PointStart(1);

n=PointStart(2);

k=PointEnd(1);

l= PointEnd(2);

LineLong=sqrt((n-m)^2+(l-k)^2);

dwAngle=atan((l-k)/(n-m+eps));

line(PointStart,PointEnd,'Color',color); %画主线

hold on

if m>n %终点在起点的右边

x= floor(n-floor(0.15*LineLong+0.5)*cos(dwAngle+3*pi/4)); %画短线段1

y= floor(l-floor(0.15*LineLong+.5)*sin(dwAngle+3*pi/4));

p=[x n];

v=[y l];

line(p,v,'Color',color)

hold on

xx=floor(n-0.15*LineLong*cos(dwAngle-3*pi/4)); %画短线段2

yy=floor(l-0.15*LineLong*sin(dwAngle-3*pi/4));

pp=[xx n];

vv=[yy l];

line(pp,vv,'Color',color)

end

if m<=n %终点在起点的左边

x= floor(n-floor(0.15*LineLong+0.5)*cos(dwAngle+pi/4)); %画短线段1 y= floor(l-floor(0.15*LineLong+.5)*sin(dwAngle+pi/4));

p=[x n];

v=[y l];

line(p,v,'Color',color)

hold on

xx=floor(n-0.15*LineLong*cos(dwAngle-pi/4)); %画短线段2

yy=floor(l-0.15*LineLong*sin(dwAngle-pi/4));

pp=[xx n];

vv=[yy l];

line(pp,vv,'Color',color)

end

附结果图片

相关主题