Image obtained by using pbm driver and then converted to png.
1 2 #pragma _ipath "." 3 #include <plcdemos.h> 4 5 6 int 7 main(int argc, char *argv[]) 8 { 9 int i, j; 10 PLFLT dtr, theta, dx, dy, r; 11 char text[4]; 12 static PLFLT x0[361], y0[361]; 13 static PLFLT x[361], y[361]; 14 15 dtr = PI / 180.0; 16 for (i = 0; i <= 360; i++) { 17 x0[i] = cos(dtr * i); 18 y0[i] = sin(dtr * i); 19 } 20 21 22 (void) plParseOpts(&argc, argv, PL_PARSE_FULL); 23 24 25 plinit(); 26 27 28 plenv(-1.3, 1.3, -1.3, 1.3, 1, -2); 29 for (i = 1; i <= 10; i++) { 30 for (j = 0; j <= 360; j++) { 31 x[j] = 0.1 * i * x0[j]; 32 y[j] = 0.1 * i * y0[j]; 33 } 34 35 36 plline(361, x, y); 37 } 38 39 plcol0(2); 40 for (i = 0; i <= 11; i++) { 41 theta = 30.0 * i; 42 dx = cos(dtr * theta); 43 dy = sin(dtr * theta); 44 45 46 pljoin(0.0, 0.0, dx, dy); 47 sprintf(text, "%d", ROUND(theta)); 48 49 50 if (dx >= -0.00001) 51 plptex(dx, dy, dx, dy, -0.15, text); 52 else 53 plptex(dx, dy, -dx, -dy, 1.15, text); 54 } 55 56 57 for (i = 0; i <= 360; i++) { 58 r = sin(dtr * (5 * i)); 59 x[i] = x0[i] * r; 60 y[i] = y0[i] * r; 61 } 62 plcol0(3); 63 plline(361, x, y); 64 65 plcol0(4); 66 plmtex("t", 2.0, 0.5, 0.5, "#frPLplot Example 3 - r(#gh)=sin 5#gh"); 67 68 69 plend(); 70 exit(0); 71 }
Code description
- 1
- $Id: x03c.c,v 1.18 2002/12/03 08:39:24 airwin Exp $ Polar plot demo.
- 5
- --------------------------------------------------------------------------*\ * main * * Generates polar plot, with 1-1 scaling. \*--------------------------------------------------------------------------
- 21
- Parse and process command line arguments
- 24
- Initialize plplot
- 27
- Set up viewport and window, but do not draw box
- 35
- Draw circles for polar grid
- 45
- Draw radial spokes for polar grid
- 49
- Write labels for angle
- 50
- Slightly off zero to avoid floating point logic flips at 90 and 270 deg.
- 56
- Draw the graph
- 68
- Close the plot at end