guyou.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include <u.h>
  2. #include <libc.h>
  3. #include "map.h"
  4. static struct place gywhem, gyehem;
  5. static struct coord gytwist;
  6. static double gyconst, gykc, gyside;
  7. static void
  8. dosquare(double z1, double z2, double *x, double *y)
  9. {
  10. double w1,w2;
  11. w1 = z1 -1;
  12. if(fabs(w1*w1+z2*z2)>.000001) {
  13. cdiv(z1+1,z2,w1,z2,&w1,&w2);
  14. w1 *= gyconst;
  15. w2 *= gyconst;
  16. if(w1<0)
  17. w1 = 0;
  18. elco2(w1,w2,gykc,1.,1.,x,y);
  19. } else {
  20. *x = gyside;
  21. *y = 0;
  22. }
  23. }
  24. int
  25. Xguyou(struct place *place, double *x, double *y)
  26. {
  27. int ew; /*which hemisphere*/
  28. double z1,z2;
  29. struct place pl;
  30. ew = place->wlon.l<0;
  31. copyplace(place,&pl);
  32. norm(&pl,ew?&gyehem:&gywhem,&gytwist);
  33. Xstereographic(&pl,&z1,&z2);
  34. dosquare(z1/2,z2/2,x,y);
  35. if(!ew)
  36. *x -= gyside;
  37. return(1);
  38. }
  39. proj
  40. guyou(void)
  41. {
  42. double junk;
  43. gykc = 1/(3+2*sqrt(2.));
  44. gyconst = -(1+sqrt(2.));
  45. elco2(-gyconst,0.,gykc,1.,1.,&gyside,&junk);
  46. gyside *= 2;
  47. latlon(0.,90.,&gywhem);
  48. latlon(0.,-90.,&gyehem);
  49. deg2rad(0.,&gytwist);
  50. return(Xguyou);
  51. }
  52. int
  53. guycut(struct place *g, struct place *og, double *cutlon)
  54. {
  55. int c;
  56. c = picut(g,og,cutlon);
  57. if(c!=1)
  58. return(c);
  59. *cutlon = 0.;
  60. if(g->nlat.c<.7071||og->nlat.c<.7071)
  61. return(ckcut(g,og,0.));
  62. return(1);
  63. }
  64. static int
  65. Xsquare(struct place *place, double *x, double *y)
  66. {
  67. double z1,z2;
  68. double r, theta;
  69. struct place p;
  70. copyplace(place,&p);
  71. if(place->nlat.l<0) {
  72. p.nlat.l = -p.nlat.l;
  73. p.nlat.s = -p.nlat.s;
  74. }
  75. if(p.nlat.l<FUZZ && fabs(p.wlon.l)>PI-FUZZ){
  76. *y = -gyside/2;
  77. *x = p.wlon.l>0?0:gyside;
  78. return(1);
  79. }
  80. Xstereographic(&p,&z1,&z2);
  81. r = sqrt(sqrt(hypot(z1,z2)/2));
  82. theta = atan2(z1,-z2)/4;
  83. dosquare(r*sin(theta),-r*cos(theta),x,y);
  84. if(place->nlat.l<0)
  85. *y = -gyside - *y;
  86. return(1);
  87. }
  88. proj
  89. square(void)
  90. {
  91. guyou();
  92. return(Xsquare);
  93. }