area_sphere.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * \file area_sphere.c
  3. *
  4. * \brief GIS Library - Sphereical area calculation routines.
  5. *
  6. * (C) 2001-2008 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public License
  9. * (>=v2). Read the file COPYING that comes with GRASS for details.
  10. *
  11. * \author GRASS GIS Development Team
  12. *
  13. * \date 1999-2008
  14. */
  15. #include <math.h>
  16. #include <grass/gis.h>
  17. #include "pi.h"
  18. static struct state {
  19. double M;
  20. } state;
  21. static struct state *st = &state;
  22. /*
  23. * r is radius of sphere, s is a scaling factor
  24. */
  25. /**
  26. * \brief Initialize calculations for sphere.
  27. *
  28. * Initializes raster area calculations for a sphere.
  29. * The radius of the sphere is <b>r</b> and <b>s</b> is a scale factor to
  30. * allow for calculations of a part of the zone (see
  31. * <i>G_begin_zone_area_on_ellipsoid()</i>).
  32. *
  33. * \param[in] r radius of sphere
  34. * \param[in] s scale factor
  35. * \return int
  36. */
  37. int G_begin_zone_area_on_sphere(double r, double s)
  38. {
  39. return (st->M = s * 2.0 * r * r * M_PI);
  40. }
  41. /**
  42. * \brief Calculates integral for area between two latitudes.
  43. *
  44. * \param[in] lat latitude
  45. * \return double
  46. */
  47. double G_darea0_on_sphere(double lat)
  48. {
  49. return (st->M * sin(Radians(lat)));
  50. }
  51. /**
  52. * \brief Calculates area between latitudes.
  53. *
  54. * This routine shows how to calculate area between two lats, but
  55. * isn't efficient for row by row since <i>G_darea0_on_sphere()</i> will
  56. * be called twice for the same lat, once as a <b>south</b> then
  57. * again as a <b>north</b>.
  58. * <br>
  59. * Returns the area between latitudes <b>north</b> and <b>south</b>
  60. * scaled by the factor <b>s</b> passed to
  61. * <i>G_begin_zone_area_on_sphere()</i>.
  62. *
  63. * \param[in] north
  64. * \param[in] south
  65. * \return double
  66. */
  67. double G_area_for_zone_on_sphere(double north, double south)
  68. {
  69. return (G_darea0_on_sphere(north) - G_darea0_on_sphere(south));
  70. }