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