lune.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <u.h>
  2. #include <libc.h>
  3. #include "map.h"
  4. int Xstereographic(struct place *place, double *x, double *y);
  5. static struct place eastpole;
  6. static struct place westpole;
  7. static double eastx, easty;
  8. static double westx, westy;
  9. static double scale;
  10. static double pwr;
  11. /* conformal map w = ((1+z)^A - (1-z)^A)/((1+z)^A + (1-z)^A),
  12. where A<1, maps unit circle onto a convex lune with x= +-1
  13. mapping to vertices of angle A*PI at w = +-1 */
  14. /* there are cuts from E and W poles to S pole,
  15. in absence of a cut routine, error is returned for
  16. points outside a polar cap through E and W poles */
  17. static Xlune(struct place *place, double *x, double *y)
  18. {
  19. double stereox, stereoy;
  20. double z1x, z1y, z2x, z2y;
  21. double w1x, w1y, w2x, w2y;
  22. double numx, numy, denx, deny;
  23. if(place->nlat.l < eastpole.nlat.l-FUZZ)
  24. return -1;
  25. Xstereographic(place, &stereox, &stereoy);
  26. stereox *= scale;
  27. stereoy *= scale;
  28. z1x = 1 + stereox;
  29. z1y = stereoy;
  30. z2x = 1 - stereox;
  31. z2y = -stereoy;
  32. cpow(z1x,z1y,&w1x,&w1y,pwr);
  33. cpow(z2x,z2y,&w2x,&w2y,pwr);
  34. numx = w1x - w2x;
  35. numy = w1y - w2y;
  36. denx = w1x + w2x;
  37. deny = w1y + w2y;
  38. cdiv(numx, numy, denx, deny, x, y);
  39. return 1;
  40. }
  41. proj
  42. lune(double lat, double theta)
  43. {
  44. deg2rad(lat, &eastpole.nlat);
  45. deg2rad(-90.,&eastpole.wlon);
  46. deg2rad(lat, &westpole.nlat);
  47. deg2rad(90. ,&westpole.wlon);
  48. Xstereographic(&eastpole, &eastx, &easty);
  49. Xstereographic(&westpole, &westx, &westy);
  50. if(fabs(easty)>FUZZ || fabs(westy)>FUZZ ||
  51. fabs(eastx+westx)>FUZZ)
  52. abort();
  53. scale = 1/eastx;
  54. pwr = theta/180;
  55. return Xlune;
  56. }