~uhh-ssd/+junk/humidity_readout

« back to all changes in this revision

Viewing changes to plplot/plplot-5.9.9/examples/d/x28d.d

  • Committer: Joachim Erfle
  • Date: 2013-07-24 13:53:41 UTC
  • Revision ID: joachim.erfle@desy.de-20130724135341-1qojpp701zsn009p
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// $Id: x28d.d 11684 2011-03-31 04:15:32Z airwin $
 
2
//
 
3
//      plmtex3, plptex3 demo.
 
4
//
 
5
// Copyright (C) 2009 Werner Smekal
 
6
// Copyright (C) 2009 Alan W. Irwin
 
7
//
 
8
// This file is part of PLplot.
 
9
//
 
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.
 
14
//
 
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.
 
19
//
 
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
 
23
//
 
24
//
 
25
 
 
26
import std.string;
 
27
import std.math;
 
28
 
 
29
import plplot;
 
30
 
 
31
//--------------------------------------------------------------------------
 
32
// main
 
33
//
 
34
// Demonstrates plotting text in 3D.
 
35
//--------------------------------------------------------------------------
 
36
int main( char[][] args )
 
37
{
 
38
    // Choose these values to correspond to tick marks.
 
39
    const int XPTS        = 2;
 
40
    const int YPTS        = 2;
 
41
    const int NREVOLUTION = 16;
 
42
    const int NROTATION   = 8;
 
43
    const int NSHEAR      = 8;
 
44
 
 
45
    PLFLT
 
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 ),
 
59
        ys, zs;
 
60
 
 
61
    // p1string must be exactly one character + the null termination
 
62
    // character.
 
63
    string pstring = "The future of our civilization depends on software freedom.";
 
64
 
 
65
    // Allocate and define the minimal x, y, and z to insure 3D box
 
66
    PLFLT[XPTS] x;
 
67
    PLFLT[YPTS] y;
 
68
 
 
69
    PLFLT[][] z = new PLFLT[][XPTS];
 
70
    for ( int i = 0; i < XPTS; i++ )
 
71
        z[i] = new PLFLT[YPTS];
 
72
 
 
73
    for ( int i = 0; i < XPTS; i++ )
 
74
        x[i] = xmin + i * xrange / ( XPTS - 1 );
 
75
 
 
76
    for ( int j = 0; j < YPTS; j++ )
 
77
        y[j] = ymin + j * yrange / ( YPTS - 1 );
 
78
 
 
79
    for ( int i = 0; i < XPTS; i++ )
 
80
        for ( int j = 0; j < YPTS; j++ )
 
81
            z[i][j] = 0.0;
 
82
 
 
83
    // Parse and process command line arguments
 
84
    plparseopts( args, PL_PARSE_FULL );
 
85
 
 
86
    plinit();
 
87
 
 
88
    // Page 1: Demonstrate inclination and shear capability pattern.
 
89
    pladv( 0 );
 
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. );
 
93
 
 
94
    plcol0( 2 );
 
95
    plbox3( "b", "", xrange, 0,
 
96
        "b", "", yrange, 0,
 
97
        "bcd", "", zrange, 0 );
 
98
 
 
99
    PLFLT x_inclination, y_inclination, z_inclination;
 
100
    PLFLT x_shear, y_shear, z_shear;
 
101
    PLFLT omega, sin_omega, cos_omega;
 
102
 
 
103
    // z = zmin.
 
104
    plschr( 0., 1.0 );
 
105
    for ( int i = 0; i < NREVOLUTION; i++ )
 
106
    {
 
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;
 
112
        z_inclination = 0.0;
 
113
        x_shear       = -0.5 * xrange * sin_omega;
 
114
        y_shear       = 0.5 * yrange * cos_omega;
 
115
        z_shear       = 0.;
 
116
        plptex3( xmid, ymid, zmin,
 
117
            x_inclination, y_inclination, z_inclination,
 
118
            x_shear, y_shear, z_shear,
 
119
            0.0, "  revolution" );
 
120
    }
 
121
 
 
122
    // x = xmax.
 
123
    plschr( 0., 1.0 );
 
124
    for ( int i = 0; i < NREVOLUTION; i++ )
 
125
    {
 
126
        omega         = ( 2. * PI * i ) / NREVOLUTION;
 
127
        sin_omega     = sin( omega );
 
128
        cos_omega     = cos( omega );
 
129
        x_inclination = 0.;
 
130
        y_inclination = -0.5 * yrange * cos_omega;
 
131
        z_inclination = 0.5 * zrange * sin_omega;
 
132
        x_shear       = 0.;
 
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" );
 
139
    }
 
140
 
 
141
    // y = ymax.
 
142
    plschr( 0., 1.0 );
 
143
    for ( int i = 0; i < NREVOLUTION; i++ )
 
144
    {
 
145
        omega         = ( 2. * PI * i ) / NREVOLUTION;
 
146
        sin_omega     = sin( omega );
 
147
        cos_omega     = cos( omega );
 
148
        x_inclination = 0.5 * xrange * cos_omega;
 
149
        y_inclination = 0.;
 
150
        z_inclination = 0.5 * zrange * sin_omega;
 
151
        x_shear       = -0.5 * xrange * sin_omega;
 
152
        y_shear       = 0.;
 
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" );
 
158
    }
 
159
 
 
160
    // Draw minimal 3D grid to finish defining the 3D box.
 
161
    plmesh( x, y, z, DRAW_LINEXY );
 
162
 
 
163
    // Page 2: Demonstrate rotation of string around its axis.
 
164
    pladv( 0 );
 
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. );
 
168
 
 
169
    plcol0( 2 );
 
170
    plbox3( "b", "", xrange, 0,
 
171
        "b", "", yrange, 0,
 
172
        "bcd", "", zrange, 0 );
 
173
 
 
174
    // y = ymax.
 
175
    plschr( 0., 1.0 );
 
176
    x_inclination = 1.;
 
177
    y_inclination = 0.;
 
178
    z_inclination = 0.;
 
179
    x_shear       = 0.;
 
180
    for ( int i = 0; i < NROTATION; i++ )
 
181
    {
 
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" );
 
192
    }
 
193
 
 
194
    // x = xmax.
 
195
    plschr( 0., 1.0 );
 
196
    x_inclination = 0.;
 
197
    y_inclination = -1.;
 
198
    z_inclination = 0.;
 
199
    y_shear       = 0.;
 
200
    for ( int i = 0; i < NROTATION; i++ )
 
201
    {
 
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" );
 
212
    }
 
213
 
 
214
    // z = zmin.
 
215
    plschr( 0., 1.0 );
 
216
    x_inclination = 1.;
 
217
    y_inclination = 0.;
 
218
    z_inclination = 0.;
 
219
    x_shear       = 0.;
 
220
    for ( int i = 0; i < NROTATION; i++ )
 
221
    {
 
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" );
 
232
    }
 
233
    // Draw minimal 3D grid to finish defining the 3D box.
 
234
    plmesh( x, y, z, DRAW_LINEXY );
 
235
 
 
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.)
 
240
    PLFLT domega = 0.05;
 
241
    pladv( 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. );
 
245
 
 
246
    plcol0( 2 );
 
247
    plbox3( "b", "", xrange, 0,
 
248
        "b", "", yrange, 0,
 
249
        "bcd", "", zrange, 0 );
 
250
 
 
251
    // y = ymax.
 
252
    plschr( 0., 1.0 );
 
253
    x_inclination = 1.;
 
254
    y_inclination = 0.;
 
255
    z_inclination = 0.;
 
256
    y_shear       = 0.;
 
257
    for ( int i = 0; i < NSHEAR; i++ )
 
258
    {
 
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" );
 
269
    }
 
270
 
 
271
    // x = xmax.
 
272
    plschr( 0., 1.0 );
 
273
    x_inclination = 0.;
 
274
    y_inclination = -1.;
 
275
    z_inclination = 0.;
 
276
    x_shear       = 0.;
 
277
    for ( int i = 0; i < NSHEAR; i++ )
 
278
    {
 
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" );
 
289
    }
 
290
 
 
291
    // z = zmin.
 
292
    plschr( 0., 1.0 );
 
293
    x_inclination = 1.;
 
294
    y_inclination = 0.;
 
295
    z_inclination = 0.;
 
296
    z_shear       = 0.;
 
297
    for ( int i = 0; i < NSHEAR; i++ )
 
298
    {
 
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" );
 
309
    }
 
310
    // Draw minimal 3D grid to finish defining the 3D box.
 
311
    plmesh( x, y, z, DRAW_LINEXY );
 
312
 
 
313
    // Page 4: Demonstrate drawing a string on a 3D path.
 
314
    pladv( 0 );
 
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. );
 
318
 
 
319
    plcol0( 2 );
 
320
    plbox3( "b", "", xrange, 0,
 
321
        "b", "", yrange, 0,
 
322
        "bcd", "", zrange, 0 );
 
323
 
 
324
    plschr( 0., 1.2 );
 
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;
 
329
    omega  = 0.;
 
330
    // 3D function is a helix of the given radius and pitch
 
331
    PLFLT radius = 0.5;
 
332
    PLFLT pitch  = 1. / ( 2. * PI );
 
333
    PLFLT xpos, ypos, zpos;
 
334
    for ( int i = 0; i < pstring.length; i++ )
 
335
    {
 
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;
 
341
 
 
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;
 
347
 
 
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.
 
351
        x_shear = 0.;
 
352
        y_shear = 0.;
 
353
        z_shear = 1.;
 
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] );
 
358
        omega += domega;
 
359
    }
 
360
    // Draw minimal 3D grid to finish defining the 3D box.
 
361
    plmesh( x, y, z, DRAW_LINEXY );
 
362
 
 
363
    // Page 5: Demonstrate plmtex3 axis labelling capability
 
364
    pladv( 0 );
 
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. );
 
368
 
 
369
    plcol0( 2 );
 
370
    plbox3( "b", "", xrange, 0,
 
371
        "b", "", yrange, 0,
 
372
        "bcd", "", zrange, 0 );
 
373
 
 
374
    plschr( 0., 1.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" );
 
387
 
 
388
    // Draw minimal 3D grid to finish defining the 3D box.
 
389
    plmesh( x, y, z, DRAW_LINEXY );
 
390
 
 
391
    plend();
 
392
    return 0;
 
393
}