ellipse

PURPOSE ^

Ellipse adds ellipses to the current plot

SYNOPSIS ^

function h=ellipse(ra,rb,ang,x0,y0,C,Nb)

DESCRIPTION ^

 Ellipse adds ellipses to the current plot

 ELLIPSE(ra,rb,ang,x0,y0) adds an ellipse with semimajor axis of ra,
 a semimajor axis of radius rb, a semimajor axis of ang, centered at
 the point x0,y0.

 The length of ra, rb, and ang should be the same. 
 If ra is a vector of length L and x0,y0 scalars, L ellipses
 are added at point x0,y0.
 If ra is a scalar and x0,y0 vectors of length M, M ellipse are with the same 
 radii are added at the points x0,y0.
 If ra, x0, y0 are vectors of the same length L=M, M ellipses are added.
 If ra is a vector of length L and x0, y0 are  vectors of length
 M~=L, L*M ellipses are added, at each point x0,y0, L ellipses of radius ra.

 ELLIPSE(ra,rb,ang,x0,y0,C)
 adds ellipses of color C. C may be a string ('r','b',...) or the RGB value. 
 If no color is specified, it makes automatic use of the colors specified by 
 the axes ColorOrder property. For several circles C may be a vector.

 ELLIPSE(ra,rb,ang,x0,y0,C,Nb), Nb specifies the number of points
 used to draw the ellipse. The default value is 300. Nb may be used
 for each ellipse individually.

 h=ELLIPSE(...) returns the handles to the ellipses.

 as a sample of how ellipse works, the following produces a red ellipse
 tipped up at a 45 deg axis from the x axis
 ellipse(1,2,pi/8,1,1,'r')

 note that if ra=rb, ELLIPSE plots a circle

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function h=ellipse(ra,rb,ang,x0,y0,C,Nb)
0002 % Ellipse adds ellipses to the current plot
0003 %
0004 % ELLIPSE(ra,rb,ang,x0,y0) adds an ellipse with semimajor axis of ra,
0005 % a semimajor axis of radius rb, a semimajor axis of ang, centered at
0006 % the point x0,y0.
0007 %
0008 % The length of ra, rb, and ang should be the same.
0009 % If ra is a vector of length L and x0,y0 scalars, L ellipses
0010 % are added at point x0,y0.
0011 % If ra is a scalar and x0,y0 vectors of length M, M ellipse are with the same
0012 % radii are added at the points x0,y0.
0013 % If ra, x0, y0 are vectors of the same length L=M, M ellipses are added.
0014 % If ra is a vector of length L and x0, y0 are  vectors of length
0015 % M~=L, L*M ellipses are added, at each point x0,y0, L ellipses of radius ra.
0016 %
0017 % ELLIPSE(ra,rb,ang,x0,y0,C)
0018 % adds ellipses of color C. C may be a string ('r','b',...) or the RGB value.
0019 % If no color is specified, it makes automatic use of the colors specified by
0020 % the axes ColorOrder property. For several circles C may be a vector.
0021 %
0022 % ELLIPSE(ra,rb,ang,x0,y0,C,Nb), Nb specifies the number of points
0023 % used to draw the ellipse. The default value is 300. Nb may be used
0024 % for each ellipse individually.
0025 %
0026 % h=ELLIPSE(...) returns the handles to the ellipses.
0027 %
0028 % as a sample of how ellipse works, the following produces a red ellipse
0029 % tipped up at a 45 deg axis from the x axis
0030 % ellipse(1,2,pi/8,1,1,'r')
0031 %
0032 % note that if ra=rb, ELLIPSE plots a circle
0033 %
0034 
0035 % written by D.G. Long, Brigham Young University, based on the
0036 % CIRCLES.m original
0037 % written by Peter Blattner, Institute of Microtechnology, University of
0038 % Neuchatel, Switzerland, blattner@imt.unine.ch
0039 
0040 
0041 % Check the number of input arguments
0042 
0043 if nargin<1,
0044   ra=[];
0045 end;
0046 if nargin<2,
0047   rb=[];
0048 end;
0049 if nargin<3,
0050   ang=[];
0051 end;
0052 
0053 %if nargin==1,
0054 %  error('Not enough arguments');
0055 %end;
0056 
0057 if nargin<5,
0058   x0=[];
0059   y0=[];
0060 end;
0061  
0062 if nargin<6,
0063   C=[];
0064 end
0065 
0066 if nargin<7,
0067   Nb=[];
0068 end
0069 
0070 % set up the default values
0071 
0072 if isempty(ra),ra=1;end;
0073 if isempty(rb),rb=1;end;
0074 if isempty(ang),ang=0;end;
0075 if isempty(x0),x0=0;end;
0076 if isempty(y0),y0=0;end;
0077 if isempty(Nb),Nb=300;end;
0078 if isempty(C),C=get(gca,'colororder');end;
0079 
0080 % work on the variable sizes
0081 
0082 x0=x0(:);
0083 y0=y0(:);
0084 ra=ra(:);
0085 rb=rb(:);
0086 ang=ang(:);
0087 Nb=Nb(:);
0088 
0089 if isstr(C),C=C(:);end;
0090 
0091 if length(ra)~=length(rb),
0092   error('length(ra)~=length(rb)');
0093 end;
0094 if length(x0)~=length(y0),
0095   error('length(x0)~=length(y0)');
0096 end;
0097 
0098 % how many inscribed elllipses are plotted
0099 
0100 if length(ra)~=length(x0)
0101   maxk=length(ra)*length(x0);
0102 else
0103   maxk=length(ra);
0104 end;
0105 
0106 % drawing loop
0107 
0108 for k=1:maxk
0109   
0110   if length(x0)==1
0111     xpos=x0;
0112     ypos=y0;
0113     radm=ra(k);
0114     radn=rb(k);
0115     if length(ang)==1
0116       an=ang;
0117     else
0118       an=ang(k);
0119     end;
0120   elseif length(ra)==1
0121     xpos=x0(k);
0122     ypos=y0(k);
0123     radm=ra;
0124     radn=rb;
0125     an=ang;
0126   elseif length(x0)==length(ra)
0127     xpos=x0(k);
0128     ypos=y0(k);
0129     radm=ra(k);
0130     radn=rb(k);
0131     an=ang(k);
0132   else
0133     rada=ra(fix((k-1)/size(x0,1))+1);
0134     radb=rb(fix((k-1)/size(x0,1))+1);
0135     an=ang(fix((k-1)/size(x0,1))+1);
0136     xpos=x0(rem(k-1,size(x0,1))+1);
0137     ypos=y0(rem(k-1,size(y0,1))+1);
0138   end;
0139 
0140   co=cos(an);
0141   si=sin(an);
0142   the=linspace(0,2*pi,Nb(rem(k-1,size(Nb,1))+1,:)+1);
0143 %  x=radm*cos(the)*co-si*radn*sin(the)+xpos;
0144 %  y=radm*cos(the)*si+co*radn*sin(the)+ypos;
0145   h(k)=line(radm*cos(the)*co-si*radn*sin(the)+xpos,radm*cos(the)*si+co*radn*sin(the)+ypos);
0146   set(h(k),'color',C(rem(k-1,size(C,1))+1,:));
0147 
0148 end;
0149

Generated on Thu 08-Apr-2010 14:35:09 by m2html © 2005