|
|
1.1 root 1: #include "map.h"
2:
3: /* Given two lat-lon pairs, find an orientation for the
4: -o option of "map" that will place those two points
5: on the equator of a standard projection, equally spaced
6: about the prime meridian. Both an erect and an inverted
7: orientation are found.
8:
9: Option -t prints out a series of
10: coordinates that follows the (great circle) track
11: in the original coordinate system,
12: followed by ".
13: This data is just right for map -t.
14: */
15: struct place pole;
16: struct coord twist;
17: int track;
18:
19: extern void doroute(double, double, double, double, double);
20:
21: void
22: dorot(double a, double b, double *x, double *y, void (*f)(struct place *))
23: {
24: struct place g;
25: deg2rad(a,&g.nlat);
26: deg2rad(b,&g.wlon);
27: (*f)(&g);
28: *x = g.nlat.l/RAD;
29: *y = g.wlon.l/RAD;
30: }
31:
32: void
33: rotate(double a, double b, double *x, double *y)
34: {
35: dorot(a,b,x,y,normalize);
36: }
37:
38: void
39: rinvert(double a, double b, double *x, double *y)
40: {
41: dorot(a,b,x,y,invert);
42: }
43:
44: main(int argc, char **argv)
45: {
46: #pragma ref argv
47: double an,aw,bn,bw;
48: track = argc>1;
49: for(;;){
50: if(scanf("%lf%lf%lf%lf",&an,&aw,&bn,&bw)!=4)
51: break;
52: doroute(-90.,an,aw,bn,bw);
53: if(!track)
54: doroute(90.,an,aw,bn,bw);
55: }
56: return 0;
57: }
58:
59: void
60: doroute(double dir, double an, double aw, double bn, double bw)
61: {
62: double an1,aw1,bn1,bw1,pn,pw;
63: double theta;
64: double cn,cw,cn1,cw1;
65: int i,n;
66: orient(an,aw,0.);
67: rotate(bn,bw,&bn1,&bw1);
68: /* printf("b %f %f\n",bn1,bw1);*/
69: orient(an,aw,bw1);
70: rinvert(0.,dir,&pn,&pw);
71: /* printf("p %f %f\n",pn,pw);*/
72: orient(pn,pw,0.);
73: rotate(an,aw,&an1,&aw1);
74: rotate(bn,bw,&bn1,&bw1);
75: theta = (aw1+bw1)/2;
76: /* printf("a %f %f \n",an1,aw1);*/
77: orient(pn,pw,theta);
78: rotate(an,aw,&an1,&aw1);
79: rotate(bn,bw,&bn1,&bw1);
80: if(fabs(aw1-bw1)>180)
81: if(theta<0.) theta+=180;
82: else theta -= 180;
83: orient(pn,pw,theta);
84: rotate(an,aw,&an1,&aw1);
85: rotate(bn,bw,&bn1,&bw1);
86: if(!track) {
87: printf("-o %.4f %.4f %.4f\n",pn,pw,theta);
88: printf("A %.4f %.4f\n",an1,aw1);
89: printf("B %.4f %.4f\n",bn1,bw1);
90: } else {
91: cn1 = 0;
92: n = 1 + fabs(bw1-aw1)/.2;
93: for(i=0;i<=n;i++) {
94: cw1 = aw1 + i*(bw1-aw1)/n;
95: rinvert(cn1,cw1,&cn,&cw);
96: printf("%f %f\n",cn,cw);
97: }
98: printf("\"\n");
99: }
100: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.