harrison.c 708 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <u.h>
  2. #include <libc.h>
  3. #include "map.h"
  4. static double v3,u2,u3,a,b; /*v=view,p=obj,u=unit.y*/
  5. static int
  6. Xharrison(struct place *place, double *x, double *y)
  7. {
  8. double p1 = -place->nlat.c*place->wlon.s;
  9. double p2 = -place->nlat.c*place->wlon.c;
  10. double p3 = place->nlat.s;
  11. double d = b + u3*p2 - u2*p3;
  12. double t;
  13. if(d < .01)
  14. return -1;
  15. t = a/d;
  16. if(v3*place->nlat.s < 1.)
  17. return -1;
  18. *y = t*p2*u2 + (v3-t*(v3-p3))*u3;
  19. *x = t*p1;
  20. if(t < 0)
  21. return 0;
  22. if(*x * *x + *y * *y > 16)
  23. return -1;
  24. return 1;
  25. }
  26. proj
  27. harrison(double r, double alpha)
  28. {
  29. u2 = cos(alpha*RAD);
  30. u3 = sin(alpha*RAD);
  31. v3 = r;
  32. b = r*u2;
  33. a = 1 + b;
  34. if(r<1.001 || a<sqrt(r*r-1))
  35. return 0;
  36. return Xharrison;
  37. }