Attachment 't04.c'
Download 1 // t04.c
2 // v0.1 KHL 2009-04-21
3 // gcc -o t04 t04.c -lm -lgd ; ./t04
4 // static drawing, though slow to compute
5 // earth and toroid around orbit
6
7 #define TITLE "M288, 1 center and 4 toroid orbits"
8 #define GIFOUT "t04.gif"
9 #define NORB 4
10 #define DELTANG 0.2
11 #define ORBWIDTH 9
12 #define ANG0 0
13 #define ANG1 90
14 #define ANG2 142
15 #define NELIP 32
16
17 #include "tor00.hc"
18
19 int main () {
20 double t_ang ;
21 int e_cnt ;
22 int orb ;
23 int norb ;
24
25 gdPoint ellipse[NELIP+2];
26
27 displaystart();
28 torstart();
29
30 gdImageGifAnimBegin( im1, gifout, 1, -1 ) ; // no repeat
31 // gdImageGifAnimBegin( im1, gifout, 1, 4 ) ; // repeat 4 times
32 // gdImageGifAnimBegin( im1, gifout, 1, 0 ) ; // continuous repeat
33
34 framestart( 90, TITLE );
35
36 // draw back portion of the orbit toroid
37
38 double acolor = 0.0 ;
39 if( NORB > 0 ) { norb = 1 + NORB ; }
40 else { norb = 1 - NORB ; }
41
42 for( t_ang=ANG0 ; t_ang < ANG2 ; t_ang += DELTANG ) {
43
44 double ecolor ;
45 if( acolor < 0.5 ) { ecolor = gray ; }
46 else {
47 ecolor = lgray ;
48 if( acolor > 14.5 ) { acolor -= 15.0 ; }
49 }
50 acolor += DELTANG ;
51
52 double angle_rad=DEG2RAD( t_ang );
53
54 // ellipse disk - since it is at an angle, we will have to draw it
55 // as a filled polygon
56
57 // ellipse disk on left
58 for( e_cnt=0 ; e_cnt < NELIP ; e_cnt++ ) {
59 double toa = angle_rad + (2.0*PI*e_cnt)/NELIP ;
60 double tos = td[ norb-1 ] * step ; // step size
61 double tor = tos * cos( toa );
62 double toy = tos * sin( toa );
63 double tox = -(major+tor)*sin( angle_rad );
64 double toz = -(major+tor)*cos( angle_rad );
65 ellipse[e_cnt] = sr0( tox, toy, toz );
66 }
67 if( ( NORB < 0 ) && ( t_ang > ( ANG2-DELTANG ) ) ) {
68 gdImageFilledPolygon( im, ellipse, NELIP, black );
69 }
70 gdImagePolygon( im, ellipse, NELIP, ecolor );
71
72
73 // ellipse disk on right
74 for( e_cnt=0 ; e_cnt < NELIP ; e_cnt++ ) {
75 double toa = -angle_rad + (2.0*PI*e_cnt)/NELIP ;
76 double tos = td[ norb-1 ] * step ; // step size
77 double tor = tos * cos( toa );
78 double toy = tos * sin( toa );
79 double tox = -(major+tor)*sin( -angle_rad );
80 double toz = -(major+tor)*cos( -angle_rad );
81 ellipse[e_cnt] = sr0( tox, toy, toz );
82 }
83 if( ( NORB < 0 ) && ( t_ang > ( ANG2-DELTANG ) ) ) {
84 gdImageFilledPolygon( im, ellipse, NELIP, black );
85 }
86 gdImagePolygon( im, ellipse, NELIP, ecolor );
87
88
89 for( orb=0 ; orb < norb ; orb++ ) {
90 // orbit spot on left
91 int tcolor = tc[orb];
92 double toa = angle_rad + DEG2RAD( ta[orb] ) ;
93 double tos = step * td[ orb ] ; // step size
94 double tor = tos * cos( toa );
95 double toy = tos * sin( toa );
96 double tox = -(major+tor)*sin( angle_rad );
97 double toz = -(major+tor)*cos( angle_rad );
98 gdPoint pto = sr0( tox, toy, toz );
99 gdImageFilledEllipse( im, pto.x, pto.y, ORBWIDTH, ORBWIDTH, tcolor);
100
101 // orbit spot on right
102 toa = -angle_rad + DEG2RAD( ta[orb] ) ;
103 tos = step * td[ orb ] ; // step size
104 tor = tos * cos( toa );
105 toy = tos * sin( toa );
106 tox = -(major+tor)*sin( -angle_rad );
107 toz = -(major+tor)*cos( -angle_rad );
108 pto = sr0( tox, toy, toz );
109 gdImageFilledEllipse( im, pto.x, pto.y, ORBWIDTH, ORBWIDTH, tcolor);
110 }
111 }
112 drawearth();
113
114 if( NORB > 0 ) {
115 // draw the rest of the center orbit
116 for( t_ang=ANG2 ; t_ang < 360.0-ANG2 ; t_ang += DELTANG ) {
117 double angle_rad=DEG2RAD( t_ang );
118 double tox = -major*sin( angle_rad );
119 double toz = -major*cos( angle_rad );
120 gdPoint pto = sr0( tox, 0.0, toz );
121 gdImageFilledEllipse( im, pto.x, pto.y, ORBWIDTH, ORBWIDTH, tc[0]);
122 }
123 }
124 sprintf( bottom, "%5.0fkm spacing between orbits", 6378.0*step/re );
125
126 frameend();
127 displayend();
128 return 0;
129 }
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.