home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / map / map.c next >
Encoding:
C/C++ Source or Header  |  1994-05-09  |  1.4 KB  |  76 lines  |  [TEXT/KAHL]

  1. #include <Quickdraw.h>
  2. # include "trigtab.h"
  3. # include <math.h>
  4. # ifndef M_PI
  5. # define M_PI 3.1415926536
  6. # endif
  7.  
  8. extern trigtab  *trig;
  9. extern int xmax,ymax;
  10.  
  11. # define degrad (180.0/M_PI)
  12.  
  13. double org_lat = -4.5;
  14. double org_lng = 55.5;
  15. double ref_lat,ref_lng,plotsize;
  16. static long end;
  17.  
  18. static double sqr(double x)
  19.     {
  20.     return(x*x);
  21.     }
  22.  
  23. void setcolor(int color)
  24.     {
  25.     }
  26.  
  27. void plot(double ref_lat, double ref_lng, double plotsize)
  28.     { 
  29.     trigtab  *tr = trig; 
  30.     double reflat = ref_lat/degrad;
  31.     double reflng = ref_lng/degrad;
  32.     double zr = cos(reflat);
  33.     double yr = sin(reflat);
  34.     double cosreflng = cos(reflng);
  35.     double sinreflng = sin(reflng);
  36.     int xmax2 = xmax/2;
  37.     int ymax2 = ymax/2;
  38.     int x2 = xmax2;
  39.     int y2 = ymax2;
  40.     double yscale = ymax2/sin(plotsize/degrad);
  41.     double xscale = yscale;
  42.     MoveTo(xmax2, ymax2);
  43.     while ((tr->color >= 0))
  44.         {
  45.         double rc = tr->cosnewlat;
  46.         double xc = rc*(tr->sinnewlng*cosreflng-tr->cosnewlng*sinreflng);
  47.         double yc = tr->sinnewlat;
  48.         double zc = rc*(tr->cosnewlng*cosreflng+tr->sinnewlng*sinreflng);
  49.         double yrot = yc*zr-zc*yr;
  50.         double sqdist = sqr(xc)+sqr(yc-yr)+sqr(zc-zr);
  51. /*
  52.         int x1 = x2;
  53.         int y1 = y2;
  54. */
  55.         x2 = xmax2+(int)(xc*xscale);
  56.         y2 = ymax2-(int)(yrot*yscale);
  57.         if (tr->color)
  58.             {
  59.                MoveTo(x2,y2);
  60.             setcolor(tr->color);
  61.             }
  62.         else
  63.             {
  64.             if ((sqdist > 0.0) && (sqdist <= 1.9) && ((xmax2 != x2)||(ymax2 != y2)))
  65.                 {
  66.                    LineTo(x2,y2);
  67.                 }
  68.             else 
  69.                 {
  70.                    MoveTo(x2,y2);
  71.                 }
  72.             }
  73.         tr++;
  74.         }
  75.     }
  76.