xref: /plan9-contrib/sys/src/cmd/map/libmap/elliptic.c (revision 219b2ee8daee37f4aad58d63f21287faa8e4ffdc)
1 #include "map.h"
2 
3 struct coord center;
4 
5 static int
6 Xelliptic(struct place *place, double *x, double *y)
7 {
8 	double r1,r2;
9 	r1 = acos(place->nlat.c*(place->wlon.c*center.c
10 		- place->wlon.s*center.s));
11 	r2 = acos(place->nlat.c*(place->wlon.c*center.c
12 		+ place->wlon.s*center.s));
13 	*x = -(r1*r1 - r2*r2)/(4*center.l);
14 	*y = (r1*r1+r2*r2)/2 - (center.l*center.l+*x**x);
15 	if(*y < 0)
16 		*y = 0;
17 	*y = sqrt(*y);
18 	if(place->nlat.l<0)
19 		*y = -*y;
20 	return(1);
21 }
22 
23 proj
24 elliptic(double l)
25 {
26 	l = fabs(l);
27 	if(l>89)
28 		return(0);
29 	if(l<1)
30 		return(Xazequidistant);
31 	deg2rad(l,&center);
32 	return(Xelliptic);
33 }
34