gmmbvl_Ellipse adds ellipses to the current plot gmmbvl_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. gmmbvl_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. gmmbvl_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=gmmbvl_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 gmmbvl_ellipse(1,2,pi/8,1,1,'r') note that if ra=rb, gmmbvl_ELLIPSE plots a circle
0001 function h = gmmbvl_ellipse(ra,rb,ang,x0,y0,C,Nb) 0002 % gmmbvl_Ellipse adds ellipses to the current plot 0003 % 0004 % gmmbvl_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 % gmmbvl_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 % gmmbvl_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=gmmbvl_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 % gmmbvl_ellipse(1,2,pi/8,1,1,'r') 0031 % 0032 % note that if ra=rb, gmmbvl_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 % NOTE: this is a slightly modified version for octave 0041 0042 % 0043 % $Name: $ 0044 0045 0046 % Check the number of input arguments 0047 0048 if nargin<1, 0049 ra=[]; 0050 end; 0051 if nargin<2, 0052 rb=[]; 0053 end; 0054 if nargin<3, 0055 ang=[]; 0056 end; 0057 0058 %if nargin==1, 0059 % error('Not enough arguments'); 0060 %end; 0061 0062 if nargin<5, 0063 x0=[]; 0064 y0=[]; 0065 end; 0066 0067 if nargin<6, 0068 C=[]; 0069 end 0070 0071 if nargin<7, 0072 Nb=[]; 0073 end 0074 0075 % set up the default values 0076 0077 if isempty(ra),ra=1;end; 0078 if isempty(rb),rb=1;end; 0079 if isempty(ang),ang=0;end; 0080 if isempty(x0),x0=0;end; 0081 if isempty(y0),y0=0;end; 0082 if isempty(Nb),Nb=300;end; 0083 %% MATLAB 0084 % if isempty(C),C=get(gca,'colororder');end; 0085 %% 0086 0087 % work on the variable sizes 0088 0089 x0=x0(:); 0090 y0=y0(:); 0091 ra=ra(:); 0092 rb=rb(:); 0093 ang=ang(:); 0094 Nb=Nb(:); 0095 0096 if isstr(C),C=C(:);end; 0097 0098 if length(ra)~=length(rb), 0099 error('length(ra)~=length(rb)'); 0100 end; 0101 if length(x0)~=length(y0), 0102 error('length(x0)~=length(y0)'); 0103 end; 0104 0105 % how many inscribed elllipses are plotted 0106 0107 if length(ra)~=length(x0) 0108 maxk=length(ra)*length(x0); 0109 else 0110 maxk=length(ra); 0111 end; 0112 0113 % drawing loop 0114 0115 for k=1:maxk 0116 0117 if length(x0)==1 0118 xpos=x0; 0119 ypos=y0; 0120 radm=ra(k); 0121 radn=rb(k); 0122 if length(ang)==1 0123 an=ang; 0124 else 0125 an=ang(k); 0126 end; 0127 elseif length(ra)==1 0128 xpos=x0(k); 0129 ypos=y0(k); 0130 radm=ra; 0131 radn=rb; 0132 an=ang; 0133 elseif length(x0)==length(ra) 0134 xpos=x0(k); 0135 ypos=y0(k); 0136 radm=ra(k); 0137 radn=rb(k); 0138 an=ang(k); 0139 else 0140 rada=ra(fix((k-1)/size(x0,1))+1); 0141 radb=rb(fix((k-1)/size(x0,1))+1); 0142 an=ang(fix((k-1)/size(x0,1))+1); 0143 xpos=x0(rem(k-1,size(x0,1))+1); 0144 ypos=y0(rem(k-1,size(y0,1))+1); 0145 end; 0146 0147 co=cos(an); 0148 si=sin(an); 0149 the=linspace(0,2*pi,Nb(rem(k-1,size(Nb,1))+1,:)+1); 0150 0151 %% OCTAVE 0152 plot(radm*cos(the)*co-si*radn*sin(the)+xpos,radm*cos(the)*si+co*radn*sin(the)+ypos,'k-'); 0153 %% 0154 0155 %% MATLAB 0156 % h(k)=line(radm*cos(the)*co-si*radn*sin(the)+xpos,radm*cos(the)*si+co*radn*sin(the)+ypos); 0157 % set(h(k),'color',C(rem(k-1,size(C,1))+1,:)); 0158 %% 0159 0160 end; 0161