plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

mercator.c (567B)


      1 #include <u.h>
      2 #include <libc.h>
      3 #include "map.h"
      4 
      5 static int
      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
     16 mercator(void)
     17 {
     18 	return(Xmercator);
     19 }
     20 
     21 static double ecc = ECC;
     22 
     23 static int
     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
     33 sp_mercator(void)
     34 {
     35 	return(Xspmercator);
     36 }