NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/basics/circles.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 %
2 % CIRCLES  plot circles at optionally input centers with required input radii.
3 %
4 %          CIRCLES(RAD) draws circles at the origin with radii RAD.
5 %
6 %          CIRCLES(XC,YC,RAD) draws circles with radii RAD and with
7 %          centers at (XC,YC).
8 %
9 % Input  : XC   - x-coord vector of circle centers (optional, See Note 4)
10 %          YC   - y-coord vector of circle centers (optional, See Note 4)
11 %          RAD  - vector of circle radii (required)
12 %          p1,v1... - parameter/value plotting pairs (optional, See Note 4)
13 %
14 % Output : HCIR - vector of handles to circles drawn.
15 %
16 %          The parameter/value pairs currently allowed in the CIRCLES
17 %          function are as follows ( default values appear in {} ) :
18 %
19 %                Color       {'r' = red}
20 %                LineStyle   {'-' = solid}
21 %                LineWidth   {0.5 points; 1 point = 1/72 inches}
22 %                MarkerSize  {6 points}
23 %
24 %          See the Matlab Reference Guide entry on the LINE command for
25 %          a complete description of parameter/value pair specification.
26 %
27 %          The idea and some of the constructs used in pv decoding
28 %          in this routine come from an unreleased MathWorks function
29 %          called polar2.m written by John L. Galenski III
30 %          and provided by Jeff Faneuff.
31 %
32 %          NOTES: 1) CIRCLES always overlays existing axes, regardless
33 %                    of the state of 'hold'.
34 %                 2) CIRCLES does not force the axis to be 'equal'.
35 %                 3) CIRCLES is a special case of the routine ELLIPSES;
36 %                    although ELLIPSES can be used to draw circles,
37 %                    CIRCLES is much faster at drawing circles because
38 %                    it does not deal with orientation and eccentricity
39 %                    parameters.
40 %                 4) If you want to specify parameter/vaule plotting
41 %                    attributes with circles at the origin, you must pass
42 %                    CIRCLES 0-vectors for the x- and y- coordinates of
43 %                    the circles.  If you don't, CIRCLES will not be able
44 %                    to decode the parameter/value sequence and you will
45 %                    probably get the following error:
46 %                                ??? Error using ==> +
47 %                                Matrix dimensions must agree.
48 %
49 % Call as: >> hcir=circles(xc,yc,rad,p1,v1,p2,v2,...)
50 %
51 % Written by : Brian O. Blanton
52 %         
53 function hcir=circles(xc,yc,rad,p1,v1,p2,v2,p3,v3,p4,v4,...
54                                p5,v5,p6,v6,p7,v7,p8,v8)
55
56 % DEFINE ERROR STRINGS
57 err1=['Need atleast radii as input.'];
58 err2=['Too many input arguments specified.'];
59 err3=['Must specify centers and radii or just radii.'];
60 err4=['Lengths of circle center vectors must be the same.'];
61 err5=['Number of circle centers and radii specified must be the same.'];
62 err6=['insufficient number of parameters or values'];
63
64 % check arguments.
65 if nargin==0
66    error(err1);
67 elseif nargin>19
68    error(err2)
69 elseif nargin==1
70    rad=xc;
71    xc=zeros(size(rad));
72    yc=zeros(size(rad));
73    flag=1;
74 elseif nargin==2
75    error(err3);
76 elseif nargin==3
77    if length(xc)~=length(yc)
78       error(err4);
79    elseif length(xc)~=length(rad)
80       error(err5);
81    end
82    flag=1;
83 else
84    flag=0;
85    npv = nargin-3;
86    if rem(npv,2)==1,error(err6);,end
87    
88    % process parameter/value pair argument list, if needed
89    PropFlag = zeros(1,4);
90    limt=npv/2;
91    for X = 1:limt
92      p = eval(['p',int2str(X)]);
93      v = eval(['v',int2str(X)]);
94      if X == 1
95        Property_Names = p;
96        Property_Value = v;
97      else
98        Property_Names = str2mat(Property_Names,p);
99        Property_Value = str2mat(Property_Value,v);
100      end
101      if strcmp(lower(p),'color')
102        PropFlag(1) = 1;
103        color = v;
104      elseif strcmp(lower(p),'linestyle')
105        PropFlag(2) = 1;
106        linestyle = v;
107      elseif strcmp(lower(p),'linewidth')
108        PropFlag(3) = 1;
109        linewidth = v;
110      elseif strcmp(lower(p),'markersize')
111        PropFlag(4) = 1;
112        markersize = v;
113      end
114    end
115
116    % Determine which properties have not been set by
117    % the user
118    Set    = find(PropFlag == 1);
119    NotSet = find(PropFlag == 0);
120
121    % Define property names and default values
122    Default_Settings =str2mat('''r''','''- ''','0.5','6');
123    Property_Names = str2mat('color','linestyle','linewidth','markersize');
124    for I = 1:length(NotSet)
125      eval([Property_Names(NotSet(I),:),'=',Default_Settings(NotSet(I),:),';'])
126    end
127 end
128
129 % force xc, yc, and rad to be column vectors.
130 xc=xc(:);
131 yc=yc(:);
132 rad=rad(:);
133
134 % t must be a row vector
135 delt=pi/24;
136 t=0:delt:2*pi;
137 t=t(:)';
138
139 % compute (0,0) origin-based circles
140 x=(rad*cos(t))';
141 y=(rad*sin(t))';
142 [nrow,ncol]=size(x);
143
144 % translate circles to input centers (xc,yc)
145 xadd=(xc*ones(size(1:nrow)))';
146 yadd=(yc*ones(size(1:nrow)))';
147 x=x+xadd;
148 y=y+yadd;
149
150 % append NaN's so we get one handle.
151 x=[x;
152    NaN*ones(size(1:ncol))];
153 y=[y;
154    NaN*ones(size(1:ncol))];
155 x=x(:);
156 y=y(:);
157
158 % draw circles and return handle in hcir.
159 if ~flag
160    hcir=line(x,y,...
161              'Color',color,...
162              'Linestyle',linestyle,...
163              'LineWidth',linewidth,...
164              'MarkerSize',markersize);
165 else
166    hcir=line(x,y);
167 end
168 set(hcir,'Tag','circles')
169 %
170 %        Brian O. Blanton
171 %        Curr. in Marine Sciences
172 %        15-1A Venable Hall
173 %        CB# 3300
174 %        Uni. of North Carolna
175 %        Chapel Hill, NC
176 %                 27599-3300
177 %
178 %        919-962-4466
179 %        blanton@marine.unc.edu
180 %
Note: See TracBrowser for help on using the browser.