gilbert.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <u.h>
  2. #include <libc.h>
  3. #include "map.h"
  4. int
  5. Xgilbert(struct place *p, double *x, double *y)
  6. {
  7. /* the interesting part - map the sphere onto a hemisphere */
  8. struct place q;
  9. q.nlat.s = tan(0.5*(p->nlat.l));
  10. if(q.nlat.s > 1) q.nlat.s = 1;
  11. if(q.nlat.s < -1) q.nlat.s = -1;
  12. q.nlat.c = sqrt(1 - q.nlat.s*q.nlat.s);
  13. q.wlon.l = p->wlon.l/2;
  14. sincos(&q.wlon);
  15. /* the dull part: present the hemisphere orthogrpahically */
  16. *y = q.nlat.s;
  17. *x = -q.wlon.s*q.nlat.c;
  18. return(1);
  19. }
  20. proj
  21. gilbert(void)
  22. {
  23. return(Xgilbert);
  24. }
  25. /* derivation of the interesting part:
  26. map the sphere onto the plane by stereographic projection;
  27. map the plane onto a half plane by sqrt;
  28. map the half plane back to the sphere by stereographic
  29. projection
  30. n,w are original lat and lon
  31. r is stereographic radius
  32. primes are transformed versions
  33. r = cos(n)/(1+sin(n))
  34. r' = sqrt(r) = cos(n')/(1+sin(n'))
  35. r'^2 = (1-sin(n')^2)/(1+sin(n')^2) = cos(n)/(1+sin(n))
  36. this is a linear equation for sin n', with solution
  37. sin n' = (1+sin(n)-cos(n))/(1+sin(n)+cos(n))
  38. use standard formula: tan x/2 = (1-cos x)/sin x = sin x/(1+cos x)
  39. to show that the right side of the last equation is tan(n/2)
  40. */