xref: /plan9/sys/src/cmd/map/libmap/lagrange.c (revision 59cc4ca53493a3c6d2349fe2b7f7c40f7dce7294)
1 #include <u.h>
2 #include <libc.h>
3 #include "map.h"
4 
5 static int
Xlagrange(struct place * place,double * x,double * y)6 Xlagrange(struct place *place, double *x, double *y)
7 {
8 	double z1,z2;
9 	double w1,w2,t1,t2;
10 	struct place p;
11 	copyplace(place,&p);
12 	if(place->nlat.l<0) {
13 		p.nlat.l = -p.nlat.l;
14 		p.nlat.s = -p.nlat.s;
15 	}
16 	Xstereographic(&p,&z1,&z2);
17 	csqrt(-z2/2,z1/2,&w1,&w2);
18 	cdiv(w1-1,w2,w1+1,w2,&t1,&t2);
19 	*y = -t1;
20 	*x = t2;
21 	if(place->nlat.l<0)
22 		*y = -*y;
23 	return(1);
24 }
25 
26 proj
lagrange(void)27 lagrange(void)
28 {
29 	return(Xlagrange);
30 }
31