param.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * - Stefano Menegon/Lorenzo Potrich: curvatures fixed Jan 2002
  3. * - FP update Lorenzo Potrich/Markus Neteler Jan 2002
  4. * - Changes line 59 for Linux - Markus Neteler Jan 1998
  5. */
  6. /*****************************************************************************/
  7. /*** ***/
  8. /*** param() ***/
  9. /*** Returns a terrain parameter based on the 6 quadratic coefficients ***/
  10. /*** that define a local trend surface. ***/
  11. /*** Jo Wood, Department of Geography, V2.0 15th December, 1994 ***/
  12. /*** ***/
  13. /*****************************************************************************/
  14. #include "param.h"
  15. #include <math.h>
  16. DCELL param(int ptype, /* Type of terrain parameter to calculate */
  17. double *coeff)
  18. { /* Set of six quadratic coefficients. */
  19. /* Quadratic function in the form of
  20. z = ax^2 + by^2 + cxy + dx + ey +f */
  21. double a = C_A * zscale, /* Rescale coefficients if a */
  22. b = C_B * zscale, /* Z scaling is required. */
  23. c = C_C * zscale, d = C_D * zscale, e = C_E * zscale, f = C_F; /* f does not need rescaling as */
  24. /* it is only used for smoothing. */
  25. switch (ptype) {
  26. case ELEV:
  27. return (f);
  28. break;
  29. case SLOPE:
  30. return (atan(sqrt(d * d + e * e)) * RAD2DEG);
  31. break;
  32. case ASPECT:
  33. return (atan2(e, d) * RAD2DEG);
  34. break;
  35. case PROFC:
  36. if ((d == 0) && (e == 0))
  37. return (0.0);
  38. else
  39. return (-2.0 * (a * d * d + b * e * e + c * e * d) /
  40. ((e * e + d * d) * pow(1.0 + d * d + e * e, 1.5)));
  41. break;
  42. case PLANC:
  43. if ((d == 0) && (e == 0))
  44. return (0.0);
  45. else
  46. return (2.0 * (b * d * d + a * e * e - c * d * e) /
  47. pow(e * e + d * d, 1.5));
  48. break;
  49. case LONGC:
  50. if ((d == 0) && (e == 0))
  51. return (0.0);
  52. else
  53. return (-2.0 * (a * d * d + b * e * e + c * d * e) /
  54. (d * d + e * e));
  55. case CROSC:
  56. if ((d == 0) && (e == 0))
  57. return (0.0);
  58. else
  59. return (-2.0 * (b * d * d + a * e * e - c * d * e) /
  60. (d * d + e * e));
  61. case MINIC:
  62. return (-a - b - sqrt((a - b) * (a - b) + c * c));
  63. case MAXIC:
  64. return (-a - b + sqrt((a - b) * (a - b) + c * c));
  65. default:
  66. return (0.0);
  67. }
  68. }