Attachment 'orbit04w.c'

Download

   1 // orbit04w.c
   2 // really fake orbit
   3 // This approximates a Kepler orbit with high eccentricity
   4 // 
   5 // Given the way I set up the palette, I would expect a white
   6 // background, but it makes a dark one.  Huh?
   7 //
   8 // compile with:  gcc -o orbit04w orbit04w.c -lgd -lpng -lm
   9 //
  10 // Uses the libgd library.  For documentation see the file:
  11 //   /usr/share/doc/gd-*/index.html  
  12 //
  13 // or the website:
  14 //   http://www.libgd.org/Reference
  15 
  16 #include "gd.h"
  17 #include "math.h"
  18 #include <stdio.h>
  19 
  20 #define  PNGFMT      "orbit04w.png"
  21 
  22 #define  XSIZE       1000
  23 #define  SEMIMAJOR   300
  24 #define  YSIZE       700
  25 #define  SATSIZE     100
  26 #define  NFRAME      120
  27 #define  SMEAR       4
  28 #define  LWID        7
  29 #define  FUDGE       5.0
  30 #define  ERROR       1e-4
  31 #define  TAIL        1.5
  32 #define  ECCENTRIC   0.20
  33 // #define  KLUDGE1     (1.0/(1.0-ECCENTRIC*ECCENTRIC))
  34 #define  KLUDGE1     (1.0+2.0/NFRAME)
  35 
  36 int main() {
  37 	FILE   *pngout    ;                /* Declare output file */
  38    char   dirname[80]     ;
  39    char   framename[80]   ;
  40 
  41    int     sun1, white, red, green, blue;  /* Declare color indexes */
  42    int     gray, dgray, dwhit, trans ;
  43    int     dred, cyan, dcyan ;
  44    double  pi2    = 8.0 * atan( 1.0 );
  45    double  delta  = pi2 / (NFRAME)  ;
  46    double  angle  ;
  47    double  dangle ;
  48    double  r      ;
  49 
  50    // compute orbit sizes
  51    
  52    double  semimajor  = SEMIMAJOR ;
  53    double  eccentric  = ECCENTRIC ;
  54    double  xsize      = eccentric*semimajor ;
  55    double  ysize      = sqrt( semimajor*semimajor - xsize*xsize );
  56    double  fudge      = (1.0-eccentric) ;
  57    double  r00        = semimajor * ( 1.0 - eccentric*eccentric ) ; 
  58 
  59    int     centery    = YSIZE/2   ;
  60    int     centerx    = XSIZE/2   ;
  61    int     dcell      = SATSIZE/2 ;
  62    int     derth      = 0.25* XSIZE;
  63 
  64    gdImagePtr im             ;                /* Declare the image */
  65    gdPoint rpoints[2*NFRAME] ;
  66    gdPoint cpoints[2*NFRAME] ;
  67    int     point ;
  68    int     frame ;
  69    int     ecount=0   ;
  70    double  object=0.0 ;
  71    double  error, error0 ;
  72    int     ox, oy ;  
  73    int     ii, jj ;
  74    int     rpoint, cpoint ;
  75 
  76    //------------------------------------------------------------
  77  
  78    // loop until end angle closes
  79    for( error = 100 ; fabs(error) > ERROR  ; ) {
  80       point = 0 ;
  81 
  82       // test computation
  83       for( angle=0.0 ; angle <= pi2 ; ) {
  84          r  = r00/( 1.0 + eccentric * cos( angle ));
  85          dangle = delta * semimajor * semimajor / ( r * r ) ;
  86          angle += dangle ;
  87          point++ ;
  88       }
  89       ecount++ ;
  90       error  = (double)(point-(NFRAME)) - ((angle-pi2)/dangle) ;
  91       delta *= ( 1.0+fudge*error/(NFRAME) ) ;
  92    }
  93 
  94    // compute points for ellipse with line segments
  95    point = 0 ;
  96    double cangle = 0.0 ;
  97    double sm     = semimajor ;
  98    for( angle=0.0 ; angle <= pi2 ; ) {
  99       r  = r00/( 1.0 + eccentric * cos( angle ));
 100       dangle = delta * semimajor * semimajor / ( r * r ) ;
 101       angle  += dangle ;
 102       cangle += delta*KLUDGE1  ;
 103       cpoints[point].x = centerx - (int) ( r   * cos(  angle ) ) ;
 104       cpoints[point].y = centery + (int) ( r   * sin(  angle ) ) ;
 105       rpoints[point].x = centerx - (int) ( sm  * cos( cangle ) ) ;
 106       rpoints[point].y = centery + (int) ( sm  * sin( cangle ) ) ;
 107       point++ ;
 108    }
 109 
 110    printf( "%5d points computed, %14.6e residual angle error, now render\n",
 111             point, angle-pi2 );
 112    
 113 
 114    im = gdImageCreateTrueColor(XSIZE, YSIZE );
 115 
 116    /* Allocate the colors sun1, white, red, green, blue */
 117    white = gdImageColorAllocate(im, 255, 255, 255);
 118    sun1  = gdImageColorAllocate(im,  51,  51, 102);
 119    red   = gdImageColorAllocate(im, 255,   0,   0);
 120    dred  = gdImageColorAllocate(im,  96,   0,   0);
 121    green = gdImageColorAllocate(im,   0, 255,   0);
 122    cyan  = gdImageColorAllocate(im,   0, 255, 255);
 123    dcyan = gdImageColorAllocate(im,   0, 160, 160);
 124    gray  = gdImageColorAllocate(im, 128, 128, 128);
 125    dwhit = gdImageColorAllocate(im, 192, 192, 192);
 126    dgray = gdImageColorAllocate(im,  48,  48,  48);
 127    trans = gdImageColorAllocate(im, 1, 1, 1);
 128 
 129    /* line thickness */
 130    gdImageSetThickness( im, LWID );
 131 
 132    /* draw orbit */
 133    gdImagePolygon( im, rpoints, point, dcyan );
 134    gdImagePolygon( im, cpoints, point, gray  );
 135 
 136    /* earth */
 137    ox = centerx ;
 138    oy = centery ;
 139    gdImageFilledArc(im,  ox    , oy   , derth, derth, 0, 360, green, gdArc );
 140 
 141 
 142    for( frame = 0 ; frame < NFRAME ; frame += NFRAME/4 ) {
 143       // server_sat smear
 144       for( ii=-SMEAR ; ii < 0 ; ii++ ) {
 145          jj=frame+ii ;
 146          if( jj < 0 ) jj += NFRAME ;
 147          ox = rpoints[jj].x ;
 148          oy = rpoints[jj].y ;
 149          gdImageFilledArc(im, ox   , oy   , dcell, dcell, 0, 360, dcyan,  gdArc);
 150 
 151 	 ox = cpoints[jj].x ;
 152          oy = cpoints[jj].y ;
 153          gdImageFilledArc(im, ox   , oy   , dcell, dcell, 0, 360, gray, gdArc);
 154       }
 155 
 156       // server_sat main
 157       ox = rpoints[frame].x ;
 158       oy = rpoints[frame].y ;
 159       gdImageFilledArc(im, ox   , oy   , dcell, dcell, 0, 360, cyan , gdArc);
 160 
 161       ox = cpoints[frame].x ;
 162       oy = cpoints[frame].y ;
 163       gdImageFilledArc(im, ox   , oy   , dcell, dcell, 0, 360, white , gdArc);
 164    }
 165    pngout = fopen( PNGFMT, "wb");
 166    gdImagePngEx( im, pngout, 1 );
 167    gdImageDestroy(im);
 168    fclose(pngout);
 169 }

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.
  • [get | view] (2013-02-12 15:26:57, 228.9 KB) [[attachment:A0_title.jpg]]
  • [get | view] (2013-02-12 15:35:39, 912.5 KB) [[attachment:B0_serversatV3a.png]]
  • [get | view] (2013-02-12 15:36:48, 1976.2 KB) [[attachment:C0_world_marble.png]]
  • [get | view] (2013-02-12 15:36:23, 1602.0 KB) [[attachment:C3_energy.png]]
  • [get | view] (2013-02-12 15:33:18, 469.6 KB) [[attachment:E0_m288xx.png]]
  • [get | view] (2013-02-12 15:32:48, 59.2 KB) [[attachment:E3_crosser.png]]
  • [get | view] (2013-02-12 15:32:06, 405.6 KB) [[attachment:H0_toroid.png]]
  • [get | view] (2013-02-12 15:34:51, 97.8 KB) [[attachment:I0_echrome.png]]
  • [get | view] (2013-02-12 15:34:08, 356.0 KB) [[attachment:J3_turn_tidal.png]]
  • [get | view] (2013-02-12 15:33:46, 281.9 KB) [[attachment:K0_lighteccentric.png]]
  • [get | view] (2013-02-12 15:31:33, 454.9 KB) [[attachment:M0_temperature.png]]
  • [get | view] (2013-02-12 15:35:14, 101.8 KB) [[attachment:M3_deploy.png]]
  • [get | view] (2013-02-12 15:30:15, 700.1 KB) [[attachment:Q0_phasedarray.png]]
  • [get | view] (2013-02-12 15:29:44, 466.0 KB) [[attachment:Q3_arrayspace.png]]
  • [get | view] (2013-02-12 15:31:06, 488.4 KB) [[attachment:R0_radiation.png]]
  • [get | view] (2013-02-12 15:30:42, 281.4 KB) [[attachment:R3_radiation.png]]
  • [get | view] (2013-02-12 15:27:28, 506.1 KB) [[attachment:S0_costdrop.png]]
  • [get | view] (2013-02-12 15:28:49, 3693.6 KB) [[attachment:U0_radar.png]]
  • [get | view] (2013-02-12 15:27:55, 416.5 KB) [[attachment:U3_rocketbody.png]]
  • [get | view] (2013-02-16 04:59:50, 14.8 KB) [[attachment:a6.c]]
  • [get | view] (2013-02-16 04:59:58, 14.6 KB) [[attachment:a7.c]]
  • [get | view] (2013-02-16 03:52:04, 16.9 KB) [[attachment:ar06.c]]
  • [get | view] (2013-02-15 23:11:57, 1.7 KB) [[attachment:crosser.gp]]
  • [get | view] (2013-02-15 23:11:40, 2.3 KB) [[attachment:crosser.pl]]
  • [get | view] (2013-02-16 04:30:17, 2.0 KB) [[attachment:darkside0.gp]]
  • [get | view] (2013-02-16 15:28:29, 2.3 KB) [[attachment:darkside0.pl]]
  • [get | view] (2013-02-16 03:38:30, 9.3 KB) [[attachment:echrome04.c]]
  • [get | view] (2013-02-16 15:29:15, 5.7 KB) [[attachment:insertrb.pl]]
  • [get | view] (2013-02-16 15:37:24, 1.9 KB) [[attachment:lj2.gp]]
  • [get | view] (2013-02-16 15:37:08, 2.3 KB) [[attachment:lj2.pl]]
  • [get | view] (2013-02-16 04:14:19, 5.1 KB) [[attachment:orbit04w.c]]
  • [get | view] (2013-02-16 04:19:08, 9.1 KB) [[attachment:pa03.c]]
  • [get | view] (2013-02-16 04:19:19, 9.1 KB) [[attachment:pa04.c]]
  • [get | view] (2013-02-12 18:22:40, 5.3 KB) [[attachment:pc02.c]]
  • [get | view] (2013-02-16 15:29:37, 2.0 KB) [[attachment:rb.gp]]
  • [get | view] (2013-02-16 02:50:27, 6.0 KB) [[attachment:sh01.c]]
  • [get | view] (2013-02-13 23:22:32, 13918.1 KB) [[attachment:ss.pdf]]
  • [get | view] (2013-02-13 23:21:58, 23.3 KB) [[attachment:ss.tex]]
  • [get | view] (2013-02-16 04:07:31, 24.1 KB) [[attachment:ss6a.c]]
  • [get | view] (2013-02-16 04:12:13, 3.4 KB) [[attachment:tor08.c]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.