Polar plot demo

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 }

Copyright 2006 Roman Putanowicz

Email: putanowr at twins.pk.edu.pl

Last Modified: Thu, 13 Jul 2006 15:35:34 CEST

Made with PubTal 3.1.3