User Tools

Site Tools


supp:octave:contrib:arrow:start

This is an old revision of the document!


Arrow

Draw vector arrows.

arrow.m
## Copyright (C) 2011 rolf.becker
## 
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
## 
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## 
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.
 
## arrow
 
## Author: rolf.becker <rolf.becker@NB-RB>
## Created: 2011-04-04
 
 
function [ ret ] = arrow (p1,p2,scal,sty,lw)
% usage: arrow (p1,p2,s, style)
% plots 2D vector arrow from p1 to p2 (arrow head)
% s: scale factor for arrow tipp hands in units, e.g. s=1
% style: 0: open arrow head, 1: closed arrow head, 2: filled
 
if size(p1)(1)==1; p1=p1'; endif;
if size(p2)(1)==1; p2=p2'; endif;
 
phi = pi/4; % angle of arrow
 
%s=0.1; % scale factor
dp=p2-p1;
l=norm(dp);
 
if l!=0
 
L=[ cos(phi/2) -sin(phi/2) ; sin(phi/2) cos(phi/2)]; % turn left
R=[ cos(-phi/2) -sin(-phi/2) ; sin(-phi/2) cos(-phi/2)]; % turn right
 
dr=R*dp/l*scal; % turn unit vector of dp left and scale with s
dl=L*dp/l*scal; % turn unit vector of dp left and scale with s
 
myhold = ishold;
 
plot([p1(1) p2(1)],[p1(2) p2(2)],"linewidth",lw); % plot line between p1 and p2
 
hold on;
 
if ((sty == 0) | (sty == 1))
	plot([p2(1)-dl(1) p2(1)],[p2(2)-dl(2) p2(2)],"linewidth",lw); % plot arrow line between p2 and p2 - dl 
	plot([p2(1)-dr(1) p2(1)],[p2(2)-dr(2) p2(2)],"linewidth",lw); % plot arrow line between p2 and p2 - dr
endif
 
if (sty == 1) % close arrow head
	plot([p2(1)-dr(1) p2(1)-dl(1)],[p2(2)-dr(2) p2(2)-dl(2)],"linewidth",lw);
 
 elseif (sty == 2) % fill arrow head
	A=[p2 p2-dl p2-dr];
	patch(A(1,:),A(2,:),'b',"linewidth",lw);
endif
 
if myhold == 0; hold off; endif
 
endif
 
endfunction
supp/octave/contrib/arrow/start.1460317547.txt.gz · Last modified: 2016/04/10 19:45 by admin