Annotation of researchv8dc/cmd/map/libmap/zcoord.c, revision 1.1.1.1

1.1       root        1: #include "map.h"
                      2: 
                      3: struct place pole;     /* map pole is tilted to here */
                      4: struct coord twist;    /* then twisted this much */
                      5: struct place ipole;    /* inverse transfrom */
                      6: struct coord itwist;
                      7: 
                      8: double cirmod();
                      9: 
                     10: orient(lat, lon, theta)
                     11: float lat, lon, theta;
                     12: {
                     13:        lat = cirmod(lat);
                     14:        if(lat>90.) {
                     15:                lat = 180. - lat;
                     16:                lon -= 180.;
                     17:                theta -= 180.;
                     18:        } else if(lat < -90.) {
                     19:                lat = -180. - lat;
                     20:                lon -= 180.;
                     21:                theta -= 180;
                     22:        }
                     23:        latlon(lat,lon,&pole);
                     24:        deg2rad(theta, &twist);
                     25:        latlon(lat,180.-theta,&ipole);
                     26:        deg2rad(180.-lon, &itwist);
                     27: }
                     28: 
                     29: latlon(lat,lon,p)
                     30: float lat,lon;
                     31: struct place *p;
                     32: {
                     33:        lat = cirmod(lat);
                     34:        if(lat>90.) {
                     35:                lat = 180. - lat;
                     36:                lon -= 180.;
                     37:        } else if(lat < -90.) {
                     38:                lat = -180. - lat;
                     39:                lon -= 180.;
                     40:        }
                     41:        deg2rad(lat,&p->nlat);
                     42:        deg2rad(lon,&p->wlon);
                     43: }
                     44: 
                     45: deg2rad(theta, coord)
                     46: float theta;
                     47: struct coord *coord;
                     48: {
                     49:        theta = cirmod(theta);
                     50:        coord->l = theta*RAD;
                     51:        if(theta==90) {
                     52:                coord->s = 1;
                     53:                coord->c = 0;
                     54:        } else if(theta== -90) {
                     55:                coord->s = -1;
                     56:                coord->c = 0;
                     57:        } else
                     58:                sincos(coord);
                     59: }
                     60: 
                     61: double cirmod(theta)
                     62: double theta;
                     63: {
                     64:        while(theta >= 180.)
                     65:                theta -= 360;
                     66:        while(theta<-180.)
                     67:                theta += 360.;
                     68:        return(theta);
                     69: }
                     70: 
                     71: sincos(coord)
                     72: struct coord *coord;
                     73: {
                     74:        coord->s = sin(coord->l);
                     75:        coord->c = cos(coord->l);
                     76: }
                     77: 
                     78: normalize(gg)
                     79: struct place *gg;
                     80: {
                     81:        norm(gg,&pole,&twist);
                     82: }
                     83: 
                     84: invert(g)
                     85: struct place *g;
                     86: {
                     87:        norm(g,&ipole,&itwist);
                     88: }
                     89: 
                     90: norm(gg,pp,tw)
                     91: struct place *gg, *pp;
                     92: struct coord *tw;
                     93: {
                     94:        register struct place *g;       /*geographic coords */
                     95:        register struct place *p;       /* new pole in old coords*/
                     96:        struct place m;                 /* standard map coords*/
                     97:        g = gg;
                     98:        p = pp;
                     99:        if(p->nlat.s == 1.) {
                    100:                if(p->wlon.l+tw->l == 0.)
                    101:                        return;
                    102:                g->wlon.l -= p->wlon.l+tw->l;
                    103:        } else {
                    104:                if(p->wlon.l != 0) {
                    105:                        g->wlon.l -= p->wlon.l;
                    106:                        sincos(&g->wlon);
                    107:                }
                    108:                m.nlat.s = p->nlat.s * g->nlat.s
                    109:                        + p->nlat.c * g->nlat.c * g->wlon.c;
                    110:                m.nlat.c = sqrt(1. - m.nlat.s * m.nlat.s);
                    111:                m.nlat.l = atan2(m.nlat.s, m.nlat.c);
                    112:                m.wlon.s = g->nlat.c * g->wlon.s;
                    113:                m.wlon.c = p->nlat.c * g->nlat.s
                    114:                        - p->nlat.s * g->nlat.c * g->wlon.c;
                    115:                m.wlon.l = atan2(m.wlon.s, - m.wlon.c)
                    116:                        - tw->l;
                    117:                *g = m;
                    118:        }
                    119:        sincos(&g->wlon);
                    120:        if(g->wlon.l>PI)
                    121:                g->wlon.l -= 2*PI;
                    122:        else if(g->wlon.l<-PI)
                    123:                g->wlon.l += 2*PI;
                    124: }
                    125: 
                    126: double tan(x)
                    127: double x;
                    128: {
                    129:        return(sin(x)/cos(x));
                    130: }
                    131: printp(g)
                    132: struct place *g;
                    133: {
                    134: printf("%.3f %.3f %.3f %.3f %.3f %.3f\n",
                    135: g->nlat.l,g->nlat.s,g->nlat.c,g->wlon.l,g->wlon.s,g->wlon.c);
                    136: }
                    137: 
                    138: copyplace(g1,g2)
                    139: struct place *g1,*g2;
                    140: {
                    141:        *g2 = *g1;
                    142: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.