1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // This file must be used under the terms of the CeCILL.
4 // This source file is licensed as described in the file COPYING, which
5 // you should have received as part of this distribution. The terms
6 // are also available at
7 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 function graypolarplot(theta,rho,z,varargin)
13 rho=1:0.2:4;theta=(0:0.02:1)*2*%pi;
14 z=30+round(theta'*(1+rho^2));
17 f.color_map=hotcolormap(128);
23 graypolarplot(theta,rho,z)
28 error(msprintf(gettext("%s: Wrong number of input argument(s): At least %d expected.\n"), "graypolarplot", 3));
34 if nv>=1 then strf=varargin(2),else strf='030',end
35 if nv>=2 then rect=varargin(4),else rect=[-R -R R R]*1.1,end
39 immediate_drawing = fig.immediate_drawing;
40 fig.immediate_drawing = "off";
43 axes.data_bounds = [rect(1), rect(2); rect(3), rect(4)];
44 axes.clip_state = "clipgrf";
46 drawGrayplot(theta,rho,z);
48 objectList = gce(); // get all the created objects to glue them at the end.
52 axes.axes_visible = ["off","off","off"];
53 axes.x_label.text = "";
54 axes.y_label.text = "";
55 axes.z_label.text = "";
60 xarc(-r,r,2*r,2*r,0,360*64)
61 objectList($ + 1) = gce();
64 xstring((r+dr)*cos(5*%pi/12),(r+dr)*sin(5*%pi/12),string(round(10*r)/10))
65 objectList($ + 1) = gce();
68 xarc(-r,r,2*r,2*r,0,360*64)
69 objectList($ + 1) = gce();
70 xstring((r+dr)*cos(5*%pi/12),(r+dr)*sin(5*%pi/12),string(round(10*r)/10))
71 objectList($ + 1) = gce();
73 rect=xstringl(0,0,'360');w=rect(3);h=rect(4);d=sqrt(w^2+h^2)/1.8
76 xsegs([0;R*cos(k*(%pi/6))],[0;R*sin(k*(%pi/6))])
77 objectList($ + 1) = gce();
80 xstring(r*cos(k*(%pi/6))-w/2,r*sin(k*(%pi/6))-h/2,string(k*30))
81 objectList($ + 1) = gce();
84 // glue all the created objects
88 fig.immediate_drawing = immediate_drawing;
92 function [x,y] = polar2Cart(rho, theta)
97 function [nbDecomp] = computeNeededDecompos(theta)
98 // Compute the needed decomposition for each patch
100 // minimal decompostion for each ring
101 nbFactesPerRingMin = 512;
103 nbDecomp = ceil(nbFactesPerRingMin / size(theta, '*'));
108 function drawGrayplot(theta, rh, z)
109 // draw only the colored part of the grayplot
111 // the aim of the function is to draw a set of curved facets
112 // In previous versions, it used arcs to perform this.
113 // However, since arcs are drawn from the origin to the outside
114 // there were overlapping and cause Z fighting in 3D.
115 // Consequenlty we now decompose each curved facet into a set of rectangular
118 nbRho = size(rho,'*');
119 nbTheta = size(theta,'*');
121 nbDecomposition = computeNeededDecompos(theta); // number of approximation facets
123 nbRefinedTheta = (nbTheta - 1) * nbDecomposition + 1;
125 // first step decompose theta in smaller intervals
126 // Actually compute cosTheta and sinTheta for speed
127 cosTheta = zeros(1, nbRefinedTheta);
128 sinTheta = zeros(1, nbRefinedTheta);
131 cosTheta(1) = cos(theta(1));
132 sinTheta(1) = sin(theta(1));
135 for i=1:(nbTheta - 1)
136 for j=1:nbDecomposition
137 t = j / nbDecomposition;
138 interpolatedTheta = t * theta(i + 1) + (1 - t) * theta(i);
139 cosTheta(index) = cos(interpolatedTheta);
140 sinTheta(index) = sin(interpolatedTheta);
146 nbQuadFacets = (nbRho - 1) * (nbRefinedTheta - 1);
149 xCoords = zeros(4, nbQuadFacets);
150 yCoords = zeros(4, nbQuadFacets);
151 colors = zeros(4, nbQuadFacets);
155 // compute the 4xnbFacets matrices for plot 3d
157 for j=1:(nbRefinedTheta - 1);
158 // get the 4 corners of a facet
159 xCoords(:,index) = [rho(i) * cosTheta(j)
160 rho(i) * cosTheta(j + 1)
161 rho(i + 1) * cosTheta(j + 1)
162 rho(i + 1) * cosTheta(j)];
164 yCoords(:,index) = [rho(i) * sinTheta(j)
165 rho(i) * sinTheta(j + 1)
166 rho(i + 1) * sinTheta(j + 1)
167 rho(i + 1) * sinTheta(j)];
169 // color is the same for each nbDecomposition facets
170 // retrieve the not refined index
171 thetaIndex = (j - 1) / nbDecomposition + 1;
172 // keep the 4 outside colors of the patch
173 // to be able to switch between average or matlab color.
174 colors(:,index) = [z(thetaIndex, i)
176 z(thetaIndex + 1, i + 1)
177 z(thetaIndex, i + 1)];
185 zCoords = zeros(4, nbQuadFacets);
187 // disable line draing and hidden color
188 plot3d(xCoords,yCoords,list(zCoords,colors));
190 gPlot.color_mode = -1; // no wireframe
191 gPlot.hiddencolor = 0; // no hidden color
192 gPlot.color_flag = 2; // average color on each facets