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

root/gliderproc/trunk/MATLAB/plots/ell_east.m

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

Initial import of Stark code.

Line 
1 %ELLIPSE_EAST plot ellipse given center, major/minor axes, orientation, etc.
2 %
3 % ELLIPSE_EAST plot ellipse given center, major and minor axes,
4 %         orientation (CCW from EAST=0 radians, and color (optional, def = 'r')
5 %
6 %  Input : xc    - ellipse x-coordinate centers, usually node x's;
7 %          yc    - ellipse y-coordinate centers, usually node y's;
8 %          umaj  - major axis component
9 %          umin  - minor axis component
10 %          orien - orientation counterclockwise from east (radians)
11 %          col   - color to draw ellipses (optional, def = 'r')
12 %
13 %          ELLIPSE_EAST plots ellipses centered at (xc,yc) with major
14 %          and minor axes (umaj,umin) at an orientation
15 %          (orien) radians counterclockwise from east.  The first
16 %          five arguments are required; the color (col) is not and
17 %          defaults to red.
18 %
19 %  Output: ELLIPSE_EAST returns the handle to the ellipse object drawn.
20 %           
21 % Call as: hell=ellipse_east(xc,yc,umaj,umin,orien,col)
22 %
23 % Written by : Brian O. Blanton
24 % CRE - added npts as argument
25 %
26 function hell=ell_east(xc,yc,umaj,umin,orien,col,npts)
27
28 % DEFINE ERROR STRINGS
29 err1=['Too many input arguments. Type "help ELLIPSE_EAST"'];
30
31 if nargin == 5
32    col='r';
33 elseif nargin>7
34    error(err1);
35 end
36 if length(xc)~=length(yc) | length(xc)~=length(umaj) | ...
37    length(umaj)~=length(umin) | length(umin)~=length(orien)
38    error('Length of xc,yc,umaj,umin,orien must be the same');
39 end
40
41 % compute non-rotated ellipses at (0,0)-origin
42 % force xc, yc, umaj, umin, orien  to be column vectors.
43 xc=xc(:);
44 yc=yc(:);
45 umaj=umaj(:);
46 umin=umin(:);
47 orien=orien(:);
48
49 % t must be a row vector
50 delt=2*pi/npts;
51 t=0:delt:2*pi;
52 %t=-pi:delt:pi;
53 t=t(:)';
54
55 % compute non-rotated ellipses at (0,0)-origin
56 x=(umaj*ones(size(t)).*cos(ones(size(orien))*t))';
57 y=(umin*ones(size(t)).*sin(ones(size(orien))*t))';
58
59 % account for orientation
60 xn=x.*cos((orien*ones(size(t)))')-y.*sin((orien*ones(size(t)))');
61 yn=x.*sin((orien*ones(size(t)))')+y.*cos((orien*ones(size(t)))');
62 x=xn;
63 y=yn;
64 [nrow,ncol]=size(x);
65
66 % translate ellipses to input centers
67 xadd=(xc*ones(size(1:nrow)))';
68 yadd=(yc*ones(size(1:nrow)))';
69 x=x+xadd;
70 y=y+yadd;
71 x=[x;
72    NaN*ones(size(1:ncol))];
73 y=[y;
74    NaN*ones(size(1:ncol))];
75 x=x(:);
76 y=y(:);
77 hell=line(x,y,'Color',col);
78
79 % assign 'ellipse' string to 'UserData' parameter of hell
80 set(hell,'UserData','ellipse');
81 set(hell,'Tag','ellipse');
82
83 %
84 %        Brian O. Blanton
85 %        Department of Marine Sciences
86 %        15-1A Venable Hall
87 %        CB# 3300
88 %        Uni. of North Carolina
89 %        Chapel Hill, NC
90 %                 27599-3300
91 %
92 %        919-962-4466
93 %        blanton@marine.unc.edu
94 %
Note: See TracBrowser for help on using the browser.