1
// $Id: x28d.d 11684 2011-03-31 04:15:32Z airwin $
3
// plmtex3, plptex3 demo.
5
// Copyright (C) 2009 Werner Smekal
6
// Copyright (C) 2009 Alan W. Irwin
8
// This file is part of PLplot.
10
// PLplot is free software; you can redistribute it and/or modify
11
// it under the terms of the GNU Library General Public License as published
12
// by the Free Software Foundation; either version 2 of the License, or
13
// (at your option) any later version.
15
// PLplot is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Library General Public License for more details.
20
// You should have received a copy of the GNU Library General Public License
21
// along with PLplot; if not, write to the Free Software
22
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31
//--------------------------------------------------------------------------
34
// Demonstrates plotting text in 3D.
35
//--------------------------------------------------------------------------
36
int main( char[][] args )
38
// Choose these values to correspond to tick marks.
41
const int NREVOLUTION = 16;
42
const int NROTATION = 8;
46
xmin = 0.0, xmax = 1.0, xmid = 0.5 * ( xmax + xmin ), xrange = xmax - xmin,
47
ymin = 0.0, ymax = 1.0, ymid = 0.5 * ( ymax + ymin ), yrange = ymax - ymin,
48
zmin = 0.0, zmax = 1.0, zmid = 0.5 * ( zmax + zmin ), zrange = zmax - zmin,
49
ysmin = ymin + 0.1 * yrange,
50
ysmax = ymax - 0.1 * yrange,
51
ysrange = ysmax - ysmin,
52
dysrot = ysrange / cast(PLFLT) ( NROTATION - 1 ),
53
dysshear = ysrange / cast(PLFLT) ( NSHEAR - 1 ),
54
zsmin = zmin + 0.1 * zrange,
55
zsmax = zmax - 0.1 * zrange,
56
zsrange = zsmax - zsmin,
57
dzsrot = zsrange / cast(PLFLT) ( NROTATION - 1 ),
58
dzsshear = zsrange / cast(PLFLT) ( NSHEAR - 1 ),
61
// p1string must be exactly one character + the null termination
63
string pstring = "The future of our civilization depends on software freedom.";
65
// Allocate and define the minimal x, y, and z to insure 3D box
69
PLFLT[][] z = new PLFLT[][XPTS];
70
for ( int i = 0; i < XPTS; i++ )
71
z[i] = new PLFLT[YPTS];
73
for ( int i = 0; i < XPTS; i++ )
74
x[i] = xmin + i * xrange / ( XPTS - 1 );
76
for ( int j = 0; j < YPTS; j++ )
77
y[j] = ymin + j * yrange / ( YPTS - 1 );
79
for ( int i = 0; i < XPTS; i++ )
80
for ( int j = 0; j < YPTS; j++ )
83
// Parse and process command line arguments
84
plparseopts( args, PL_PARSE_FULL );
88
// Page 1: Demonstrate inclination and shear capability pattern.
90
plvpor( -0.15, 1.15, -0.05, 1.05 );
91
plwind( -1.2, 1.2, -0.8, 1.5 );
92
plw3d( 1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45. );
95
plbox3( "b", "", xrange, 0,
97
"bcd", "", zrange, 0 );
99
PLFLT x_inclination, y_inclination, z_inclination;
100
PLFLT x_shear, y_shear, z_shear;
101
PLFLT omega, sin_omega, cos_omega;
105
for ( int i = 0; i < NREVOLUTION; i++ )
107
omega = ( 2. * PI * i ) / NREVOLUTION;
108
sin_omega = sin( omega );
109
cos_omega = cos( omega );
110
x_inclination = 0.5 * xrange * cos_omega;
111
y_inclination = 0.5 * yrange * sin_omega;
113
x_shear = -0.5 * xrange * sin_omega;
114
y_shear = 0.5 * yrange * cos_omega;
116
plptex3( xmid, ymid, zmin,
117
x_inclination, y_inclination, z_inclination,
118
x_shear, y_shear, z_shear,
119
0.0, " revolution" );
124
for ( int i = 0; i < NREVOLUTION; i++ )
126
omega = ( 2. * PI * i ) / NREVOLUTION;
127
sin_omega = sin( omega );
128
cos_omega = cos( omega );
130
y_inclination = -0.5 * yrange * cos_omega;
131
z_inclination = 0.5 * zrange * sin_omega;
133
y_shear = 0.5 * yrange * sin_omega;
134
z_shear = 0.5 * zrange * cos_omega;
135
plptex3( xmax, ymid, zmid,
136
x_inclination, y_inclination, z_inclination,
137
x_shear, y_shear, z_shear,
138
0.0, " revolution" );
143
for ( int i = 0; i < NREVOLUTION; i++ )
145
omega = ( 2. * PI * i ) / NREVOLUTION;
146
sin_omega = sin( omega );
147
cos_omega = cos( omega );
148
x_inclination = 0.5 * xrange * cos_omega;
150
z_inclination = 0.5 * zrange * sin_omega;
151
x_shear = -0.5 * xrange * sin_omega;
153
z_shear = 0.5 * zrange * cos_omega;
154
plptex3( xmid, ymax, zmid,
155
x_inclination, y_inclination, z_inclination,
156
x_shear, y_shear, z_shear,
157
0.0, " revolution" );
160
// Draw minimal 3D grid to finish defining the 3D box.
161
plmesh( x, y, z, DRAW_LINEXY );
163
// Page 2: Demonstrate rotation of string around its axis.
165
plvpor( -0.15, 1.15, -0.05, 1.05 );
166
plwind( -1.2, 1.2, -0.8, 1.5 );
167
plw3d( 1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45. );
170
plbox3( "b", "", xrange, 0,
172
"bcd", "", zrange, 0 );
180
for ( int i = 0; i < NROTATION; i++ )
182
omega = ( 2. * PI * i ) / NROTATION;
183
sin_omega = sin( omega );
184
cos_omega = cos( omega );
185
y_shear = 0.5 * yrange * sin_omega;
186
z_shear = 0.5 * zrange * cos_omega;
187
zs = zsmax - dzsrot * cast(PLFLT) i;
188
plptex3( xmid, ymax, zs,
189
x_inclination, y_inclination, z_inclination,
190
x_shear, y_shear, z_shear,
191
0.5, "rotation for y = y#dmax#u" );
200
for ( int i = 0; i < NROTATION; i++ )
202
omega = ( 2. * PI * i ) / NROTATION;
203
sin_omega = sin( omega );
204
cos_omega = cos( omega );
205
x_shear = 0.5 * xrange * sin_omega;
206
z_shear = 0.5 * zrange * cos_omega;
207
zs = zsmax - dzsrot * cast(PLFLT) i;
208
plptex3( xmax, ymid, zs,
209
x_inclination, y_inclination, z_inclination,
210
x_shear, y_shear, z_shear,
211
0.5, "rotation for x = x#dmax#u" );
220
for ( int i = 0; i < NROTATION; i++ )
222
omega = ( 2. * PI * i ) / NROTATION;
223
sin_omega = sin( omega );
224
cos_omega = cos( omega );
225
y_shear = 0.5 * yrange * cos_omega;
226
z_shear = 0.5 * zrange * sin_omega;
227
ys = ysmax - dysrot * cast(PLFLT) i;
228
plptex3( xmid, ys, zmin,
229
x_inclination, y_inclination, z_inclination,
230
x_shear, y_shear, z_shear,
231
0.5, "rotation for z = z#dmin#u" );
233
// Draw minimal 3D grid to finish defining the 3D box.
234
plmesh( x, y, z, DRAW_LINEXY );
236
// Page 3: Demonstrate shear of string along its axis.
237
// Work around xcairo and pngcairo (but not pscairo) problems for
238
// shear vector too close to axis of string. (N.B. no workaround
239
// would be domega = 0.)
242
plvpor( -0.15, 1.15, -0.05, 1.05 );
243
plwind( -1.2, 1.2, -0.8, 1.5 );
244
plw3d( 1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45. );
247
plbox3( "b", "", xrange, 0,
249
"bcd", "", zrange, 0 );
257
for ( int i = 0; i < NSHEAR; i++ )
259
omega = domega + ( 2. * PI * i ) / NSHEAR;
260
sin_omega = sin( omega );
261
cos_omega = cos( omega );
262
x_shear = 0.5 * xrange * sin_omega;
263
z_shear = 0.5 * zrange * cos_omega;
264
zs = zsmax - dzsshear * cast(PLFLT) i;
265
plptex3( xmid, ymax, zs,
266
x_inclination, y_inclination, z_inclination,
267
x_shear, y_shear, z_shear,
268
0.5, "shear for y = y#dmax#u" );
277
for ( int i = 0; i < NSHEAR; i++ )
279
omega = domega + ( 2. * PI * i ) / NSHEAR;
280
sin_omega = sin( omega );
281
cos_omega = cos( omega );
282
y_shear = -0.5 * yrange * sin_omega;
283
z_shear = 0.5 * zrange * cos_omega;
284
zs = zsmax - dzsshear * cast(PLFLT) i;
285
plptex3( xmax, ymid, zs,
286
x_inclination, y_inclination, z_inclination,
287
x_shear, y_shear, z_shear,
288
0.5, "shear for x = x#dmax#u" );
297
for ( int i = 0; i < NSHEAR; i++ )
299
omega = domega + ( 2. * PI * i ) / NSHEAR;
300
sin_omega = sin( omega );
301
cos_omega = cos( omega );
302
y_shear = 0.5 * yrange * cos_omega;
303
x_shear = 0.5 * xrange * sin_omega;
304
ys = ysmax - dysshear * cast(PLFLT) i;
305
plptex3( xmid, ys, zmin,
306
x_inclination, y_inclination, z_inclination,
307
x_shear, y_shear, z_shear,
308
0.5, "shear for z = z#dmin#u" );
310
// Draw minimal 3D grid to finish defining the 3D box.
311
plmesh( x, y, z, DRAW_LINEXY );
313
// Page 4: Demonstrate drawing a string on a 3D path.
315
plvpor( -0.15, 1.15, -0.05, 1.05 );
316
plwind( -1.2, 1.2, -0.8, 1.5 );
317
plw3d( 1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 40., -30. );
320
plbox3( "b", "", xrange, 0,
322
"bcd", "", zrange, 0 );
325
// domega controls the spacing between the various characters of the
326
// string and also the maximum value of omega for the given number
327
// of characters in *pstring.
328
domega = 2. * PI / pstring.length;
330
// 3D function is a helix of the given radius and pitch
332
PLFLT pitch = 1. / ( 2. * PI );
333
PLFLT xpos, ypos, zpos;
334
for ( int i = 0; i < pstring.length; i++ )
336
sin_omega = sin( omega );
337
cos_omega = cos( omega );
338
xpos = xmid + radius * sin_omega;
339
ypos = ymid - radius * cos_omega;
340
zpos = zmin + pitch * omega;
342
// In general, the inclination is proportional to the derivative of
343
// the position wrt theta.
344
x_inclination = radius * cos_omega;;
345
y_inclination = radius * sin_omega;
346
z_inclination = pitch;
348
// The shear vector should be perpendicular to the 3D line with Z
349
// component maximized, but for low pitch a good approximation is
350
// a constant vector that is parallel to the Z axis.
354
plptex3( xpos, ypos, zpos,
355
x_inclination, y_inclination, z_inclination,
356
x_shear, y_shear, z_shear,
357
0.5, pstring[i..i + 1] );
360
// Draw minimal 3D grid to finish defining the 3D box.
361
plmesh( x, y, z, DRAW_LINEXY );
363
// Page 5: Demonstrate plmtex3 axis labelling capability
365
plvpor( -0.15, 1.15, -0.05, 1.05 );
366
plwind( -1.2, 1.2, -0.8, 1.5 );
367
plw3d( 1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45. );
370
plbox3( "b", "", xrange, 0,
372
"bcd", "", zrange, 0 );
375
plmtex3( "xp", 3.0, 0.5, 0.5, "Arbitrarily displaced" );
376
plmtex3( "xp", 4.5, 0.5, 0.5, "primary X-axis label" );
377
plmtex3( "xs", -2.5, 0.5, 0.5, "Arbitrarily displaced" );
378
plmtex3( "xs", -1.0, 0.5, 0.5, "secondary X-axis label" );
379
plmtex3( "yp", 3.0, 0.5, 0.5, "Arbitrarily displaced" );
380
plmtex3( "yp", 4.5, 0.5, 0.5, "primary Y-axis label" );
381
plmtex3( "ys", -2.5, 0.5, 0.5, "Arbitrarily displaced" );
382
plmtex3( "ys", -1.0, 0.5, 0.5, "secondary Y-axis label" );
383
plmtex3( "zp", 4.5, 0.5, 0.5, "Arbitrarily displaced" );
384
plmtex3( "zp", 3.0, 0.5, 0.5, "primary Z-axis label" );
385
plmtex3( "zs", -2.5, 0.5, 0.5, "Arbitrarily displaced" );
386
plmtex3( "zs", -1.0, 0.5, 0.5, "secondary Z-axis label" );
388
// Draw minimal 3D grid to finish defining the 3D box.
389
plmesh( x, y, z, DRAW_LINEXY );