1## plmtex3, plptex3 demo
2##
3## Copyright (C) 2007 Alan Irwin
4## Copyright (C) 2007 Andrew Ross
5##
6##
7## This file is part of PLplot.
8##
9## PLplot is free software; you can redistribute it and/or modify
10## it under the terms of the GNU Library General Public License as published
11## by the Free Software Foundation; either version 2 of the License, or
12## (at your option) any later version.
13##
14## PLplot is distributed in the hope that it will be useful,
15## but WITHOUT ANY WARRANTY; without even the implied warranty of
16## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17## GNU Library General Public License for more details.
18##
19## You should have received a copy of the GNU Library General Public License
20## along with PLplot; if not, write to the Free Software
21## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22##
23
241;
25
26## Demonstrate plotting text in 3D
27
28function ix28c
29
30## Choose these values to correspond to tick marks
31  XPTS = 2;
32  YPTS = 2;
33  NREVOLUTION = 16;
34  NROTATION = 8;
35  NSHEAR = 8;
36
37  ## PLplot constants used in this example
38  DRAW_LINEXY = 3;
39
40  xmin = 0.0;
41  xmax = 1.0;
42  xmid = 0.5*(xmin+xmax);
43  xrange = xmax-xmin;
44
45  ymin = 0.0;
46  ymax = 1.0;
47  ymid = 0.5*(ymin+ymax);
48  yrange = ymax-ymin;
49
50  zmin = 0.0;
51  zmax = 1.0;
52  zmid = 0.5*(zmin+zmax);
53  zrange = zmax-zmin;
54
55  ysmin = ymin + 0.1 * yrange;
56  ysmax = ymax - 0.1 * yrange;
57  ysrange = ysmax - ysmin;
58  dysrot = ysrange / ( NROTATION - 1 );
59  dysshear = ysrange / ( NSHEAR - 1 );
60  zsmin = zmin + 0.1 * zrange;
61  zsmax = zmax - 0.1 * zrange;
62  zsrange = zsmax - zsmin;
63  dzsrot = zsrange / ( NROTATION - 1 );
64  dzsshear = zsrange / ( NSHEAR - 1 );
65
66  pstring = "The future of our civilization depends on software freedom.";
67
68  x = xmin + (0:(XPTS-1))*xrange/(XPTS-1);
69  y = ymin + (0:(XPTS-1))*yrange/(YPTS-1);
70
71  z = zeros(XPTS,YPTS);
72
73  ## Parse and process command line arguments
74
75  ## (void) plparseopts(&argc, argv, PL_PARSE_FULL);
76
77  plinit();
78
79  ## Page 1: Demonstrate inclination and shear capability pattern.
80
81  pladv(0);
82  plvpor(-0.15, 1.15, -0.05, 1.05);
83  plwind(-1.2, 1.2, -0.8, 1.5);
84  plw3d(1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45.);
85
86  plcol0(2);
87  plbox3("b", "", xrange, 0,
88	 "b", "", yrange, 0,
89	 "bcd", "", zrange, 0);
90
91  ## z = zmin.
92  plschr(0., 1.0);
93  for i = 0:NREVOLUTION-1
94    omega = 2.*pi*(i/NREVOLUTION);
95    sin_omega = sin(omega);
96    cos_omega = cos(omega);
97    x_inclination = 0.5*xrange*cos_omega;
98    y_inclination = 0.5*yrange*sin_omega;
99    z_inclination = 0.;
100    x_shear = -0.5*xrange*sin_omega;
101    y_shear = 0.5*yrange*cos_omega;
102    z_shear = 0.;
103    plptex3(xmid, ymid, zmin,
104	    x_inclination, y_inclination, z_inclination,
105	    x_shear, y_shear, z_shear,
106	    0.0, "  revolution");
107  endfor
108  ## x = xmax.
109  plschr(0., 1.0);
110  for i=0:NREVOLUTION-1
111    omega = 2.*pi*(i/NREVOLUTION);
112    sin_omega = sin(omega);
113    cos_omega = cos(omega);
114    x_inclination = 0.;
115    y_inclination = -0.5*yrange*cos_omega;
116    z_inclination = 0.5*zrange*sin_omega;
117    x_shear = 0.;
118    y_shear = 0.5*yrange*sin_omega;
119    z_shear = 0.5*zrange*cos_omega;
120    plptex3(xmax, ymid, zmid,
121	    x_inclination, y_inclination, z_inclination,
122	    x_shear, y_shear, z_shear,
123	    0.0, "  revolution");
124  endfor
125
126  ## y = ymax.
127  plschr(0., 1.0);
128  for i = 0:NREVOLUTION-1
129    omega = 2.*pi*(i/NREVOLUTION);
130    sin_omega = sin(omega);
131    cos_omega = cos(omega);
132    x_inclination = 0.5*xrange*cos_omega;
133    y_inclination = 0.;
134    z_inclination = 0.5*zrange*sin_omega;
135    x_shear = -0.5*xrange*sin_omega;
136    y_shear = 0.;
137    z_shear = 0.5*zrange*cos_omega;
138    plptex3(
139	    xmid, ymax, zmid,
140	    x_inclination, y_inclination, z_inclination,
141	    x_shear, y_shear, z_shear,
142	    0.0, "  revolution");
143  endfor
144  ## Draw minimal 3D grid to finish defining the 3D box.
145  plmesh(x', y', z', DRAW_LINEXY);
146
147  ## Page 2: Demonstrate rotation of string around its axis.
148  pladv(0);
149  plvpor(-0.15, 1.15, -0.05, 1.05);
150  plwind(-1.2, 1.2, -0.8, 1.5);
151  plw3d(1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45.);
152
153  plcol0(2);
154  plbox3("b", "", xrange, 0,
155	 "b", "", yrange, 0,
156	 "bcd", "", zrange, 0);
157
158  ## y = ymax.
159  plschr(0., 1.0);
160  x_inclination = 1.;
161  y_inclination = 0.;
162  z_inclination = 0.;
163  x_shear = 0.;
164  for i = 0:NROTATION-1
165    omega = 2.*pi*(i/NROTATION);
166    sin_omega = sin(omega);
167    cos_omega = cos(omega);
168    y_shear = 0.5*yrange*sin_omega;
169    z_shear = 0.5*zrange*cos_omega;
170    zs = zsmax - dzsrot*i;
171    plptex3(
172	    xmid, ymax, zs,
173	    x_inclination, y_inclination, z_inclination,
174	    x_shear, y_shear, z_shear,
175	    0.5, "rotation for y = y#dmax#u");
176  endfor
177
178  ## x = xmax.
179  plschr(0., 1.0);
180  x_inclination = 0.;
181  y_inclination = -1.;
182  z_inclination = 0.;
183  y_shear = 0.;
184  for i = 0:NROTATION-1
185    omega = 2.*pi*(i/NROTATION);
186    sin_omega = sin(omega);
187    cos_omega = cos(omega);
188    x_shear = 0.5*xrange*sin_omega;
189    z_shear = 0.5*zrange*cos_omega;
190    zs = zsmax - dzsrot*i;
191    plptex3(
192	    xmax, ymid, zs,
193	    x_inclination, y_inclination, z_inclination,
194	    x_shear, y_shear, z_shear,
195	    0.5, "rotation for x = x#dmax#u");
196  endfor
197
198  ## z = zmin.
199  plschr(0., 1.0);
200  x_inclination = 1.;
201  y_inclination = 0.;
202  z_inclination = 0.;
203  x_shear = 0.;
204  for i = 0:NROTATION-1
205    omega = 2.*pi*(i/NROTATION);
206    sin_omega = sin(omega);
207    cos_omega = cos(omega);
208    y_shear = 0.5*yrange*cos_omega;
209    z_shear = 0.5*zrange*sin_omega;
210    ys = ysmax - dysrot*i;
211    plptex3(
212	    xmid, ys, zmin,
213	    x_inclination, y_inclination, z_inclination,
214	    x_shear, y_shear, z_shear,
215	    0.5, "rotation for z = z#dmin#u");
216  endfor
217  ## Draw minimal 3D grid to finish defining the 3D box.
218  plmesh(x', y', z', DRAW_LINEXY);
219
220  ## Page 3: Demonstrate shear of string along its axis.
221  ## Work around xcairo and pngcairo (but not pscairo) problems for
222  ## shear vector too close to axis of string. (N.B. no workaround
223  ## would be domega = 0.)
224  domega = 0.05;
225  pladv(0);
226  plvpor(-0.15, 1.15, -0.05, 1.05);
227  plwind(-1.2, 1.2, -0.8, 1.5);
228  plw3d(1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45.);
229
230  plcol0(2);
231  plbox3("b", "", xrange, 0,
232	 "b", "", yrange, 0,
233	 "bcd", "", zrange, 0);
234
235  ## y = ymax.
236  plschr(0., 1.0);
237  x_inclination = 1.;
238  y_inclination = 0.;
239  z_inclination = 0.;
240  y_shear = 0.;
241  for i = 0:NSHEAR-1
242    omega = domega + 2.*pi*(i/NSHEAR);
243    sin_omega = sin(omega);
244    cos_omega = cos(omega);
245    x_shear = 0.5*xrange*sin_omega;
246    z_shear = 0.5*zrange*cos_omega;
247    zs = zsmax-dzsshear*i;
248    plptex3(
249	    xmid, ymax, zs,
250	    x_inclination, y_inclination, z_inclination,
251	    x_shear, y_shear, z_shear,
252	    0.5, "shear for y = y#dmax#u");
253  endfor
254
255  ## x = xmax.
256  plschr(0., 1.0);
257  x_inclination = 0.;
258  y_inclination = -1.;
259  z_inclination = 0.;
260  x_shear = 0.;
261  for i = 0:NSHEAR-1
262    omega = domega + 2.*pi*(i/NSHEAR);
263    sin_omega = sin(omega);
264    cos_omega = cos(omega);
265    y_shear = -0.5*yrange*sin_omega;
266    z_shear = 0.5*zrange*cos_omega;
267    zs = zsmax-dzsshear*i;
268    plptex3(
269	    xmax, ymid, zs,
270	    x_inclination, y_inclination, z_inclination,
271	    x_shear, y_shear, z_shear,
272	    0.5, "shear for x = x#dmax#u");
273  endfor
274
275  ## z = zmin.
276  plschr(0., 1.0);
277  x_inclination = 1.;
278  y_inclination = 0.;
279  z_inclination = 0.;
280  z_shear = 0.;
281  for i = 0:NSHEAR-1
282    omega = domega + 2.*pi*(i/NSHEAR);
283    sin_omega = sin(omega);
284    cos_omega = cos(omega);
285    y_shear = 0.5*yrange*cos_omega;
286    x_shear = 0.5*xrange*sin_omega;
287    ys = ysmax-dysshear*i;
288    plptex3(
289	    xmid, ys, zmin,
290	    x_inclination, y_inclination, z_inclination,
291	    x_shear, y_shear, z_shear,
292	    0.5, "shear for z = z#dmin#u");
293  endfor
294  ## Draw minimal 3D grid to finish defining the 3D box.
295  plmesh(x', y', z', DRAW_LINEXY);
296
297  ## Page 4: Demonstrate drawing a string on a 3D path.
298  pladv(0);
299  plvpor(-0.15, 1.15, -0.05, 1.05);
300  plwind(-1.2, 1.2, -0.8, 1.5);
301  plw3d(1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 40., -30.);
302
303  plcol0(2);
304  plbox3("b", "", xrange, 0,
305	 "b", "", yrange, 0,
306	 "bcd", "", zrange, 0);
307
308  plschr(0., 1.2);
309  ## domega controls the spacing between the various characters of the
310  ## string and also the maximum value of omega for the given number
311  ## of characters in pstring.
312  domega = 2.*pi/length(pstring);
313  omega = 0.;
314  ## 3D function is a helix of the given radius and pitch
315  radius = 0.5;
316  pitch = 1./(2.*pi);
317  for i=1:length(pstring)
318    sin_omega = sin(omega);
319    cos_omega = cos(omega);
320    xpos = xmid + radius*sin_omega;
321    ypos = ymid - radius*cos_omega;
322    zpos = zmin + pitch*omega;
323    ## In general, the inclination is proportional to the derivative of
324    ## the position wrt theta.
325    x_inclination = radius*cos_omega;
326    y_inclination = radius*sin_omega;
327    z_inclination = pitch;
328    ## The shear vector should be perpendicular to the 3D line with Z
329    ## component maximized, but for low pitch a good approximation is
330    ## a constant vector that is parallel to the Z axis.
331    x_shear = 0.;
332    y_shear = 0.;
333    z_shear = 1.;
334    p1string = pstring(i:i);
335    plptex3(
336	    xpos, ypos, zpos,
337	    x_inclination, y_inclination, z_inclination,
338	    x_shear, y_shear, z_shear,
339	    0.5, p1string);
340    omega += domega;
341  endfor
342  ## Draw minimal 3D grid to finish defining the 3D box.
343  plmesh(x', y', z', DRAW_LINEXY);
344
345  ## Page 5: Demonstrate plmtex3 axis labelling capability
346  pladv(0);
347  plvpor(-0.15, 1.15, -0.05, 1.05);
348  plwind(-1.2, 1.2, -0.8, 1.5);
349  plw3d(1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45.);
350
351  plcol0(2);
352  plbox3("b", "", xrange, 0,
353	 "b", "", yrange, 0,
354	 "bcd", "", zrange, 0);
355
356  plschr(0., 1.0);
357  plmtex3("xp", 3.0, 0.5, 0.5, "Arbitrarily displaced");
358  plmtex3("xp", 4.5, 0.5, 0.5, "primary X-axis label");
359  plmtex3("xs", -2.5, 0.5, 0.5, "Arbitrarily displaced");
360  plmtex3("xs", -1.0, 0.5, 0.5, "secondary X-axis label");
361  plmtex3("yp", 3.0, 0.5, 0.5, "Arbitrarily displaced");
362  plmtex3("yp", 4.5, 0.5, 0.5, "primary Y-axis label");
363  plmtex3("ys", -2.5, 0.5, 0.5, "Arbitrarily displaced");
364  plmtex3("ys", -1.0, 0.5, 0.5, "secondary Y-axis label");
365  plmtex3("zp", 4.5, 0.5, 0.5, "Arbitrarily displaced");
366  plmtex3("zp", 3.0, 0.5, 0.5, "primary Z-axis label");
367  plmtex3("zs", -2.5, 0.5, 0.5, "Arbitrarily displaced");
368  plmtex3("zs", -1.0, 0.5, 0.5, "secondary Z-axis label");
369  ## Draw minimal 3D grid to finish defining the 3D box.
370  plmesh(x', y', z', DRAW_LINEXY);
371
372  ## Clean up.
373
374  plend1();
375
376endfunction
377
378ix28c
379