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