Subversion Repositories seema-scanner

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
209 jakw 1
function h=ellipse(ra,rb,ang,x0,y0,C,Nb)
2
% Ellipse adds ellipses to the current plot
3
%
4
% ELLIPSE(ra,rb,ang,x0,y0) adds an ellipse with semimajor axis of ra,
5
% a semimajor axis of radius rb, a semimajor axis of ang, centered at
6
% the point x0,y0.
7
%
8
% The length of ra, rb, and ang should be the same. 
9
% If ra is a vector of length L and x0,y0 scalars, L ellipses
10
% are added at point x0,y0.
11
% If ra is a scalar and x0,y0 vectors of length M, M ellipse are with the same 
12
% radii are added at the points x0,y0.
13
% If ra, x0, y0 are vectors of the same length L=M, M ellipses are added.
14
% If ra is a vector of length L and x0, y0 are  vectors of length
15
% M~=L, L*M ellipses are added, at each point x0,y0, L ellipses of radius ra.
16
%
17
% ELLIPSE(ra,rb,ang,x0,y0,C)
18
% adds ellipses of color C. C may be a string ('r','b',...) or the RGB value. 
19
% If no color is specified, it makes automatic use of the colors specified by 
20
% the axes ColorOrder property. For several circles C may be a vector.
21
%
22
% ELLIPSE(ra,rb,ang,x0,y0,C,Nb), Nb specifies the number of points
23
% used to draw the ellipse. The default value is 300. Nb may be used
24
% for each ellipse individually.
25
%
26
% h=ELLIPSE(...) returns the handles to the ellipses.
27
%
28
% as a sample of how ellipse works, the following produces a red ellipse
29
% tipped up at a 45 deg axis from the x axis
30
% ellipse(1,2,pi/8,1,1,'r')
31
%
32
% note that if ra=rb, ELLIPSE plots a circle
33
%
34
 
35
% written by D.G. Long, Brigham Young University, based on the
36
% CIRCLES.m original 
37
% written by Peter Blattner, Institute of Microtechnology, University of 
38
% Neuchatel, Switzerland, blattner@imt.unine.ch
39
 
40
 
41
% Check the number of input arguments 
42
 
43
if nargin<1,
44
  ra=[];
45
end;
46
if nargin<2,
47
  rb=[];
48
end;
49
if nargin<3,
50
  ang=[];
51
end;
52
 
53
%if nargin==1,
54
%  error('Not enough arguments');
55
%end;
56
 
57
if nargin<5,
58
  x0=[];
59
  y0=[];
60
end;
61
 
62
if nargin<6,
63
  C=[];
64
end
65
 
66
if nargin<7,
67
  Nb=[];
68
end
69
 
70
% set up the default values
71
 
72
if isempty(ra),ra=1;end;
73
if isempty(rb),rb=1;end;
74
if isempty(ang),ang=0;end;
75
if isempty(x0),x0=0;end;
76
if isempty(y0),y0=0;end;
77
if isempty(Nb),Nb=300;end;
78
if isempty(C),C=get(gca,'colororder');end;
79
 
80
% work on the variable sizes
81
 
82
x0=x0(:);
83
y0=y0(:);
84
ra=ra(:);
85
rb=rb(:);
86
ang=ang(:);
87
Nb=Nb(:);
88
 
89
if isstr(C),C=C(:);end;
90
 
91
if length(ra)~=length(rb),
92
  error('length(ra)~=length(rb)');
93
end;
94
if length(x0)~=length(y0),
95
  error('length(x0)~=length(y0)');
96
end;
97
 
98
% how many inscribed elllipses are plotted
99
 
100
if length(ra)~=length(x0)
101
  maxk=length(ra)*length(x0);
102
else
103
  maxk=length(ra);
104
end;
105
 
106
% drawing loop
107
 
108
for k=1:maxk
109
 
110
  if length(x0)==1
111
    xpos=x0;
112
    ypos=y0;
113
    radm=ra(k);
114
    radn=rb(k);
115
    if length(ang)==1
116
      an=ang;
117
    else
118
      an=ang(k);
119
    end;
120
  elseif length(ra)==1
121
    xpos=x0(k);
122
    ypos=y0(k);
123
    radm=ra;
124
    radn=rb;
125
    an=ang;
126
  elseif length(x0)==length(ra)
127
    xpos=x0(k);
128
    ypos=y0(k);
129
    radm=ra(k);
130
    radn=rb(k);
131
    an=ang(k)
132
  else
133
    rada=ra(fix((k-1)/size(x0,1))+1);
134
    radb=rb(fix((k-1)/size(x0,1))+1);
135
    an=ang(fix((k-1)/size(x0,1))+1);
136
    xpos=x0(rem(k-1,size(x0,1))+1);
137
    ypos=y0(rem(k-1,size(y0,1))+1);
138
  end;
139
 
140
  co=cos(an);
141
  si=sin(an);
142
  the=linspace(0,2*pi,Nb(rem(k-1,size(Nb,1))+1,:)+1);
143
%  x=radm*cos(the)*co-si*radn*sin(the)+xpos;
144
%  y=radm*cos(the)*si+co*radn*sin(the)+ypos;
145
  h(k)=line(radm*cos(the)*co-si*radn*sin(the)+xpos,radm*cos(the)*si+co*radn*sin(the)+ypos);
146
  set(h(k),'color',C(rem(k-1,size(C,1))+1,:));
147
 
148
end;
149