-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcomprose.m
135 lines (120 loc) · 4.38 KB
/
comprose.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
function ho=comprose(x,y,n,w,az,varargin)
%COMPROSE Compass rose plot
%
% COMPROSE(X,Y,N,W,AZ) adds a compass rose on current axis located at
% position X,Y with N points (N is 1, 4, 8 or 16), width W (radius)
% and North pointing to azimuth AZ (in degree, AZ = 0 means an arrow
% pointing to positive Y-axis direction, rotating clockwise).
%
% COMPROSE(...,FS) adds Cardinal directions with font size FS.
%
% COMPROSE(...,'param1',value1,'param2',value2,...) specifies any
% additionnal properties of the Patch using standard parameter/value
% pairs. Note that 'FaceColor' concerns only the default black-filled
% parts of the drawing.
%
% H=COMPROSE(...) returns a Nx3 matrix of object handles: first column
% addresses solid filled patches, second column for white patches, third
% column for Cardinal direction text.
%
% Examples:
% comprose(0,0,8,.5,10)
%
% comprose(2,-1,1,2,0,20,'LineWidth',2,'FaceColor',.5*[1,1,1])
%
% h = comprose(1,2.5,16,1,-10);
% set(h(:,1),'FaceColor',[0,.5,.5],'EdgeColor',.5*[1,1,1])
% set(h(:,2),'FaceColor',.9*[1,1,1])
%
% See also PATCH.
%
% Author: Francois Beauducel <[email protected]>
% Created: 2012-06-24
% Updated: 2012-07-01
% Copyright (c) 2012, François Beauducel, covered by BSD License.
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
if nargin < 5
error('Not enough input arguments.')
end
if nargin > 5 & isnumeric(varargin{1})
fs = varargin{1};
varargin = varargin(2:end);
else
fs = 0;
end
if ~isnumeric(x) | ~isnumeric(y) | ~isnumeric(n) | ~isnumeric(w) | ~isnumeric(az)
error('X,Y,N,W, and AZ must be numeric.')
end
if all(n ~= [1,4,8,16])
error('N must be equal to 1, 4, 8 or 16.')
end
hh = [];
for k = n:-1:1
h = branch(x,y,k,w,az,fs,varargin{:});
hh = [hh;h];
end
if nargout > 0
ho = hh;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function h = branch(x,y,k,w,az,fs,varargin)
cpt = {'N','E','S','W','NE','SE','SW','NW', ...
'NNE','ENE','ESE','SSE','SSW','WSW','WNW','NNW'};
cph = {'center','left','center','right','left','left','right','right', ...
'left','left','left','left','right','right','right','right'};
cpv = {'bottom','middle','top','middle','bottom','top','top','bottom', ...
'bottom','bottom','top','top','top','top','bottom','bottom'};
if k <= 4
a = (k-1)*90 + az;
else
if k <= 8
a = (k-8)*90 - 45 + az;
w = w*.8;
fs = fs*.6;
else
a = (k-16)*45 - 22.5 + az;
w = w*.6;
fs = fs*.4;
end
end
r = .15;
xx = w*[0 0 r];
yy = w*[0 1 r];
x1 = xx*cosd(a) + yy*sind(a);
y1 = -xx*sind(a) + yy*cosd(a);
x2 = -xx*cosd(a) + yy*sind(a);
y2 = xx*sind(a) + yy*cosd(a);
h(1) = patch(x1 + x,y1 + y,'k',varargin{:});
h(2) = patch(x2 + x,y2 + y,'k',varargin{:},'FaceColor','w');
% Cardinal points
xp = 1.03*x1(2) + x;
yp = 1.03*y1(2) + y;
h(3) = text(xp,yp,cpt{k}, ...
'HorizontalAlignment',cph{k},'VerticalAlignment',cpv{k},'Rotation',-az);
if fs > 0
set(h(3),'FontSize',fs','FontWeight','bold')
else
set(h(3),'Visible','off')
end