aspect.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. ** Original Algorithm: H. Mitasova, L. Mitas, J. Hofierka, M. Zlocha
  3. ** GRASS Implementation: J. Caplan, M. Ruesink 1995
  4. **
  5. ** US Army Construction Engineering Research Lab, University of Illinois
  6. **
  7. ** Copyright M. Ruesink, J. Caplan, H. Mitasova, L. Mitas, J. Hofierka,
  8. ** M. Zlocha 1995
  9. **
  10. **This program is free software; you can redistribute it and/or
  11. **modify it under the terms of the GNU General Public License
  12. **as published by the Free Software Foundation; either version 2
  13. **of the License, or (at your option) any later version.
  14. **
  15. **This program is distributed in the hope that it will be useful,
  16. **but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. **MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. **GNU General Public License for more details.
  19. **
  20. **You should have received a copy of the GNU General Public License
  21. **along with this program; if not, write to the Free Software
  22. **Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. **
  24. */
  25. #include <math.h>
  26. #include <grass/gis.h>
  27. #include "r.flow.h"
  28. DCELL aspect_fly(DCELL * n, DCELL * c, DCELL * s, double d)
  29. {
  30. double xslope = ((n[-1] + c[-1] + c[-1] + s[-1]) -
  31. (n[1] + c[1] + c[1] + s[1])) / (8 * d);
  32. double yslope = ((s[-1] + s[0] + s[0] + s[1]) -
  33. (n[-1] + n[0] + n[0] + n[1])) / (8 * region.ns_res);
  34. double asp;
  35. if (!yslope)
  36. if (!xslope)
  37. asp = UNDEF;
  38. else if (xslope > 0)
  39. asp = parm.up ? 270. : 90.;
  40. else
  41. asp = parm.up ? 90. : 270.;
  42. else if ((asp = atan2(xslope, yslope) / DEG2RAD) < 0.)
  43. asp += 360.;
  44. return asp;
  45. }