1 // 3-d line and point plot demo. Adapted from x08c.c.
2 //
3
4 #include "plcdemos.h"
5
6 static int opt[] = { 1, 0, 1, 0 };
7 static PLFLT alt[] = { 20.0, 35.0, 50.0, 65.0 };
8 static PLFLT az[] = { 30.0, 40.0, 50.0, 60.0 };
9
10 void test_poly( int k );
11
12 //--------------------------------------------------------------------------
13 // main
14 //
15 // Does a series of 3-d plots for a given data set, with different
16 // viewing options in each plot.
17 //--------------------------------------------------------------------------
18
19 #define NPTS 1000
20
21 int
22 main( int argc, char *argv[] )
23 {
24 int i, k;
25 PLFLT *x, *y, *z;
26 PLFLT r;
27 char title[80];
28
main(int argc,char * argv[])29 // Parse and process command line arguments
30
31 (void) plparseopts( &argc, argv, PL_PARSE_FULL );
32
33 // Initialize plplot
34
35 plinit();
36
37 for ( k = 0; k < 4; k++ )
38 test_poly( k );
39
40 x = (PLFLT *) malloc( NPTS * sizeof ( PLFLT ) );
41 y = (PLFLT *) malloc( NPTS * sizeof ( PLFLT ) );
42 z = (PLFLT *) malloc( NPTS * sizeof ( PLFLT ) );
43
44 // From the mind of a sick and twisted physicist...
45
46 for ( i = 0; i < NPTS; i++ )
47 {
48 z[i] = -1. + 2. * i / NPTS;
49
50 // Pick one ...
51
52 // r = 1. - ( (PLFLT) i / (PLFLT) NPTS );
53 r = z[i];
54
55 x[i] = r * cos( 2. * M_PI * 6. * i / NPTS );
56 y[i] = r * sin( 2. * M_PI * 6. * i / NPTS );
57 }
58
59 for ( k = 0; k < 4; k++ )
60 {
61 pladv( 0 );
62 plvpor( 0.0, 1.0, 0.0, 0.9 );
63 plwind( -1.0, 1.0, -0.9, 1.1 );
64 plcol0( 1 );
65 plw3d( 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, alt[k], az[k] );
66 plbox3( "bnstu", "x axis", 0.0, 0,
67 "bnstu", "y axis", 0.0, 0,
68 "bcdmnstuv", "z axis", 0.0, 0 );
69
70 plcol0( 2 );
71
72 if ( opt[k] )
73 {
74 plline3( NPTS, x, y, z );
75 }
76 else
77 {
78 // U+22C5 DOT OPERATOR.
79 plstring3( NPTS, x, y, z, "⋅" );
80 }
81
82 plcol0( 3 );
83 sprintf( title, "#frPLplot Example 18 - Alt=%.0f, Az=%.0f",
84 alt[k], az[k] );
85 plmtex( "t", 1.0, 0.5, 0.5, title );
86 }
87
88 // Clean up
89 free( (void *) x );
90 free( (void *) y );
91 free( (void *) z );
92
93 plend();
94
95 exit( 0 );
96 }
97
98 void test_poly( int k )
99 {
100 PLFLT *x, *y, *z;
101 int i, j;
102 PLFLT pi, two_pi;
103 PLINT draw[][4] = { { 1, 1, 1, 1 },
104 { 1, 0, 1, 0 },
105 { 0, 1, 0, 1 },
106 { 1, 1, 0, 0 } };
107
108 pi = M_PI, two_pi = 2. * pi;
109
110 x = (PLFLT *) malloc( 5 * sizeof ( PLFLT ) );
111 y = (PLFLT *) malloc( 5 * sizeof ( PLFLT ) );
112 z = (PLFLT *) malloc( 5 * sizeof ( PLFLT ) );
113
114 pladv( 0 );
115 plvpor( 0.0, 1.0, 0.0, 0.9 );
116 plwind( -1.0, 1.0, -0.9, 1.1 );
117 plcol0( 1 );
118 plw3d( 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, alt[k], az[k] );
119 plbox3( "bnstu", "x axis", 0.0, 0,
120 "bnstu", "y axis", 0.0, 0,
121 "bcdmnstuv", "z axis", 0.0, 0 );
122
123 plcol0( 2 );
124
125 #define THETA( a ) ( two_pi * ( a ) / 20. )
126 #define PHI( a ) ( pi * ( a ) / 20.1 )
127
128 //
129 // x = r sin(phi) cos(theta)
130 // y = r sin(phi) sin(theta)
131 // z = r cos(phi)
132 // r = 1 :=)
133 //
134
135 for ( i = 0; i < 20; i++ )
136 {
137 for ( j = 0; j < 20; j++ )
138 {
139 x[0] = sin( PHI( j ) ) * cos( THETA( i ) );
140 y[0] = sin( PHI( j ) ) * sin( THETA( i ) );
141 z[0] = cos( PHI( j ) );
142
143 x[1] = sin( PHI( j + 1 ) ) * cos( THETA( i ) );
144 y[1] = sin( PHI( j + 1 ) ) * sin( THETA( i ) );
145 z[1] = cos( PHI( j + 1 ) );
146
147 x[2] = sin( PHI( j + 1 ) ) * cos( THETA( i + 1 ) );
148 y[2] = sin( PHI( j + 1 ) ) * sin( THETA( i + 1 ) );
149 z[2] = cos( PHI( j + 1 ) );
150
151 x[3] = sin( PHI( j ) ) * cos( THETA( i + 1 ) );
152 y[3] = sin( PHI( j ) ) * sin( THETA( i + 1 ) );
153 z[3] = cos( PHI( j ) );
154
155 x[4] = sin( PHI( j ) ) * cos( THETA( i ) );
156 y[4] = sin( PHI( j ) ) * sin( THETA( i ) );
157 z[4] = cos( PHI( j ) );
158
159 plpoly3( 5, x, y, z, draw[k], 1 );
160 }
161 }
162
163 plcol0( 3 );
164 plmtex( "t", 1.0, 0.5, 0.5, "unit radius sphere" );
165
166 // Clean up
167 free( (void *) x );
168 free( (void *) y );
169 free( (void *) z );
170 }
171