annotate aim-mat/tools/ellipse.m @ 4:537f939baef0 tip

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