northarrow

PURPOSE ^

NORTHARROW - overlay an arrow pointing north on the current plot

SYNOPSIS ^

function northarrow(structure)

DESCRIPTION ^

NORTHARROW - overlay an arrow pointing north on the current plot

   Usage:
      northarrow(structure)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function northarrow(structure)
0002 %NORTHARROW - overlay an arrow pointing north on the current plot
0003 %
0004 %   Usage:
0005 %      northarrow(structure)
0006 
0007 %Go through structure and fill missing arguments
0008 if length(structure)<3
0009     error('plotmodel error message: the position or the length of the North arrow is missing');
0010 elseif length(structure)==3
0011     structure(4)=0.5; %default ratio headarrow/length
0012     structure(5)=structure(3)/10; %default width =length/10
0013 elseif length(structure)==4
0014     structure(5)=structure(3)/10; %default width =length/10
0015 elseif length(structure)>5
0016     error('plotmodel error message: to many input arguments for northarrow: [x0 y0 length [ratio [width]]]');
0017 end
0018 
0019 %retrieve north arrow parameters
0020 x0=structure(1);
0021 y0=structure(2);
0022 lengtharrow=structure(3);
0023 ratio=structure(4);
0024 width=structure(5);
0025 
0026 %Figure out angle to point towards north
0027 ang=atan2(y0,x0);
0028 
0029 %Build the two points Ap and Bp
0030 x=zeros(2,1);
0031 y=zeros(2,1);
0032 x(1)=x0;
0033 y(1)=y0;
0034 
0035 x(2)=x(1)+lengtharrow*cos(ang);
0036 y(2)=y(1)+lengtharrow*sin(ang);
0037 
0038 Ap=[x(1)
0039    y(1)];
0040 Bp=[x(2)
0041    y(2)];
0042 
0043 %Build arrowhead first
0044 ang2=150*2*pi/360;
0045 rotation=[cos(ang2), sin(ang2); -sin(ang2), cos(ang2)];
0046 
0047 E=ratio*rotation*(Bp-Ap)+Bp;
0048 F=Bp;
0049 G=ratio*rotation'*(Bp-Ap)+Bp;
0050 H=Bp/4+E*3/8+G*3/8;
0051 
0052 %Build rectangle
0053 u=Bp-Ap;
0054 alpha=atan2(u(2),u(1));
0055 
0056 A=Ap-[-width/2*sin(alpha)
0057    width/2*cos(alpha)];
0058  B=H-[-width/2*sin(alpha)
0059    width/2*cos(alpha)];
0060 C=H+[-width/2*sin(alpha)
0061    width/2*cos(alpha)];
0062 D=Ap+[-width/2*sin(alpha)
0063    width/2*cos(alpha)];
0064 
0065 %Plot arrow
0066 hold on
0067 p1=patch([A(1) B(1) C(1) D(1)],[A(2) B(2) C(2) D(2)],'Black');
0068 p2=patch([E(1) F(1) G(1) H(1)],[E(2) F(2) G(2) H(2)],'Black');
0069 
0070 %Text North
0071 xN=max([A(1) D(1) E(1) F(1) G(1)])+ratio/3*lengtharrow;
0072 yN=mean([A(2) F(2) H(2)]);
0073 text(xN,yN,'North','FontSize',16,'FontWeight','b');

Generated on Sun 29-Mar-2009 20:22:55 by m2html © 2003