1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2010 - DIGITEO - Manuel Juliachs
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution. The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
10 function polarplot(theta,rho,style,strf,leg,rect)
14 rho=sin(2*theta).*cos(2*theta)
19 if size(theta,1)==1 then
22 if size(rho,1)==1 then
33 if exists("style","local")==1 then
34 opts=[opts,"style=style"]
36 if exists("strf","local")==1 then
37 opts=[opts,"strf=strf"]
40 if exists("leg","local")==1 then
43 if exists("rect","local")==1 then
44 opts=[opts,"rect=rect"]
47 if exists("frameflag","local")==1 then
48 opts=[opts,"frameflag=frameflag"]
52 if size(opts,2)<rhs-2 then
53 error(msprintf(gettext("%s: Wrong value for input argument: ''%s'', ''%s'', ''%s'', ''%s'' or ''%s'' expected.\n"),"polarplot","style","strf","leg","rect","frameflag"));
56 // Some default values:
57 Amin=0 // starting angle for the frame
58 dA=360 // span of the angular frame
59 nn=4 // number of quadrants to be drawn
67 // Angle at which Radial labels will be displayed
68 A=round(atan((ymin+ymax)/2,(xmin+xmax)/2)/%pi*180/45)*45;
69 dx=-0.5, dy=-0.5 // H & V shifts in string-width and string-height units
73 // Determines quadrant(s) to be drawn
101 L=(xmax-xmin)*1.1; if L==0, L=2*rm*1.1; end
102 H=(ymax-ymin)*1.1; if H==0, H=2*rm*1.1; end
103 x0=(xmin+xmax)/2; y0=(ymin+ymax)/2;
104 rect=[x0-L/2 y0-H/2 x0+L/2 y0+H/2]
106 // Special case: data aligned on the x or y axis
108 if (ymax-ymin)<2*e, // on x axis
125 n=find(Q); // id numbers of quadrants to be drawn
126 nn=length(n) // number of quadrants to be drawn
132 if n==1, A=90, dx=-1.1, dy=-0.5
133 elseif n==2, A=90, dx=0.2, dy=-0.5
134 elseif n==3, A=270, dx=0.2, dy=-0.5
135 else A=270, dx=-1.1, dy=-0.5
140 if n(2)==2, //A=90, dx=0.1, dy=-0.5
141 else Amin=-90, A=90, dx=-1.2, dy=-0.5, end
142 elseif n(1)==2, A=90, dx=0.2, dy=-0.5
143 else A=0, dx=-0.5, dy=0.2
148 opts=[opts,"rect=rect"]
151 if isstrf& isframeflag then
152 error(msprintf(gettext("%s: ''%s'' cannot be used with ''%s''.\n"),"polarplot","frameflag","strf"));
156 opts=[opts,"axesflag=axesflag"],
158 if ~(isstrf|isframeflag) then
160 opts=[opts,"frameflag=frameflag"],
163 execstr("plot2d(x,y,"+strcat(opts,",")+")")
165 a.data_bounds=[rect(1:2);rect(3:4)]
166 a.margins=[0.07 0.07 0.12 0.07]
168 fcolor=color("grey70");
172 // Radial values for the frame:
173 fmt_in=format(), format("v",9)
174 // Tunning for smart values:
175 p=floor(log10(abs(rm)));
183 if m-k*dm < dm/5, k=k-1, end
185 // Tuning for smart 10^ display using LaTeX instead of D+## exponential display
188 [v,k]=max(length(Rtxt)), tmp=xstringl(0,0,Rtxt(k))
190 if dm<1, dm=dm*10, p=p-1, end
191 tmp=string(R/10^p)+"108"
192 [v,k]=max(length(tmp)), tmp=xstringl(0,0,tmp(k))
193 Rtxt="$\scriptstyle "+string(R/10^p)+"\:.10^{"+string(p)+"}$";
196 format(fmt_in(2),fmt_in(1)) // Restoring entrance format
199 // Drawing & labelling the radial frame
203 xarc(-r,r,2*r,2*r,Amin*64,dA*64)
204 e = gce();,e.line_style=3
207 e.line_style=1; // solid outer arc
209 xstring(r*cosd(A)+w*dx, r*sind(A)+h*dy, Rtxt(k))
211 e.clip_state = "off";
216 if nn<3, eA=10, else eA=30; end // adaptative angular sampling
217 an=linspace(Amin,Amin+dA,round(dA/eA)+1);
219 if nn>2, tmp=find(abs(an-360)<eA/10); an(tmp)=[]; end
220 // Adjusting H-shifts of angular labels
221 tmp=xstringl(0,0,"360");
223 rL=rm*1.03; // Radius of angular labels
224 for k=an // draws and labels angular rays
225 xsegs([0;rm*cosd(k)],[0;rm*sind(k)])
226 e = gce(); e.segs_color=fcolor; e.line_style=3;
227 xstring((rL+w/2)*cosd(k)-w/2, (rL+h/2)*sind(k)-h/2, string(k))
229 e.clip_state = "off";