xref: /plan9/sys/src/cmd/map/libmap/mercator.c (revision 59cc4ca53493a3c6d2349fe2b7f7c40f7dce7294)
1 #include <u.h>
2 #include <libc.h>
3 #include "map.h"
4 
5 static int
Xmercator(struct place * place,double * x,double * y)6 Xmercator(struct place *place, double *x, double *y)
7 {
8 	if(fabs(place->nlat.l) > 80.*RAD)
9 		return(-1);
10 	*x = -place->wlon.l;
11 	*y = 0.5*log((1+place->nlat.s)/(1-place->nlat.s));
12 	return(1);
13 }
14 
15 proj
mercator(void)16 mercator(void)
17 {
18 	return(Xmercator);
19 }
20 
21 static double ecc = ECC;
22 
23 static int
Xspmercator(struct place * place,double * x,double * y)24 Xspmercator(struct place *place, double *x, double *y)
25 {
26 	if(Xmercator(place,x,y) < 0)
27 		return(-1);
28 	*y += 0.5*ecc*log((1-ecc*place->nlat.s)/(1+ecc*place->nlat.s));
29 	return(1);
30 }
31 
32 proj
sp_mercator(void)33 sp_mercator(void)
34 {
35 	return(Xspmercator);
36 }
37