1 |
function hell=ellipse(xc,yc,umaj,umin,orien,varargin) |
---|
2 |
%ELLIPSE plot ellipse given center, major/minor axes, orientation, etc. |
---|
3 |
% ELLIPSE plot ellipse given center, major and minor axes, |
---|
4 |
% orientation, 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 clockwise from north (radians) |
---|
11 |
% |
---|
12 |
% ELLIPSE plots ellipses centered at (xc,yc) with major |
---|
13 |
% and minor axes (umaj,umin) at an orientation |
---|
14 |
% (orien) radians clockwise from north. The first |
---|
15 |
% five arguments are required; the color (col) is not and |
---|
16 |
% defaults to red. |
---|
17 |
% |
---|
18 |
% Output: ELLIPSE returns the handle to the ellipse object drawn. |
---|
19 |
% |
---|
20 |
% Call as: hell=ellipse(xc,yc,umaj,umin,orien,col) |
---|
21 |
% |
---|
22 |
% Written by : Brian O. Blanton |
---|
23 |
% |
---|
24 |
|
---|
25 |
% DEFINE ERROR STRINGS |
---|
26 |
err1=['Too many input arguments. Type "help ELLIPSE"']; |
---|
27 |
|
---|
28 |
if nargin>6 |
---|
29 |
error(err1); |
---|
30 |
end |
---|
31 |
if length(xc)~=length(yc) | length(xc)~=length(umaj) | ... |
---|
32 |
length(umaj)~=length(umin) | length(umin)~=length(orien) |
---|
33 |
error('Length of xc,yc,umaj,umin,orien must be the same'); |
---|
34 |
end |
---|
35 |
|
---|
36 |
% force xc, yc, umaj, umin, orien to be column vectors. |
---|
37 |
xc=xc(:); |
---|
38 |
yc=yc(:); |
---|
39 |
umaj=umaj(:); |
---|
40 |
umin=umin(:); |
---|
41 |
orien=orien(:); |
---|
42 |
|
---|
43 |
% t must be a row vector |
---|
44 |
delt=pi/20; |
---|
45 |
t=0:delt:2*pi; |
---|
46 |
%t=-pi:delt:pi; |
---|
47 |
t=t(:)'; |
---|
48 |
|
---|
49 |
% compute un-rotated ellipses at (0,0)-origin |
---|
50 |
x=(umaj*ones(size(t)).*cos(ones(size(orien))*t))'; |
---|
51 |
y=(umin*ones(size(t)).*sin(ones(size(orien))*t))'; |
---|
52 |
|
---|
53 |
% change orientation to be CW from north; |
---|
54 |
% a temp kludge |
---|
55 |
orien=-orien+pi/2; |
---|
56 |
|
---|
57 |
% account for orientation |
---|
58 |
xn=x.*cos((orien*ones(size(t)))')-y.*sin((orien*ones(size(t)))'); |
---|
59 |
yn=x.*sin((orien*ones(size(t)))')+y.*cos((orien*ones(size(t)))'); |
---|
60 |
x=xn; |
---|
61 |
y=yn; |
---|
62 |
[nrow,ncol]=size(x); |
---|
63 |
|
---|
64 |
% translate ellipses to centers |
---|
65 |
xadd=(xc*ones(size(1:nrow)))'; |
---|
66 |
yadd=(yc*ones(size(1:nrow)))'; |
---|
67 |
x=x+xadd; |
---|
68 |
y=y+yadd; |
---|
69 |
x=[x; |
---|
70 |
NaN*ones(size(1:ncol))]; |
---|
71 |
y=[y; |
---|
72 |
NaN*ones(size(1:ncol))]; |
---|
73 |
x=x(:); |
---|
74 |
y=y(:); |
---|
75 |
hell=line(x,y,varargin{:}); |
---|
76 |
|
---|
77 |
% assign 'ellipse' string to 'UserData' parameter of hell |
---|
78 |
set(hell,'UserData','ellipse'); |
---|
79 |
set(hell,'Tag','ellipse'); |
---|
80 |
|
---|
81 |
% |
---|
82 |
%LabSig Brian O. Blanton |
---|
83 |
% Department of Marine Sciences |
---|
84 |
% 12-7 Venable Hall |
---|
85 |
% CB# 3300 |
---|
86 |
% University of North Carolina |
---|
87 |
% Chapel Hill, NC |
---|
88 |
% 27599-3300 |
---|
89 |
% |
---|
90 |
% brian_blanton@unc.edu |
---|
91 |
% |
---|