latitudeToWebMercatorFraction.glsl 1.1 KB

123456789101112131415161718192021
  1. /**
  2. * Computes the fraction of a Web Wercator rectangle at which a given geodetic latitude is located.
  3. *
  4. * @name czm_latitudeToWebMercatorFraction
  5. * @glslFunction
  6. *
  7. * @param {float} latitude The geodetic latitude, in radians.
  8. * @param {float} southMercatorY The Web Mercator coordinate of the southern boundary of the rectangle.
  9. * @param {float} oneOverMercatorHeight The total height of the rectangle in Web Mercator coordinates.
  10. *
  11. * @returns {float} The fraction of the rectangle at which the latitude occurs. If the latitude is the southern
  12. * boundary of the rectangle, the return value will be zero. If it is the northern boundary, the return
  13. * value will be 1.0. Latitudes in between are mapped according to the Web Mercator projection.
  14. */
  15. float czm_latitudeToWebMercatorFraction(float latitude, float southMercatorY, float oneOverMercatorHeight)
  16. {
  17. float sinLatitude = sin(latitude);
  18. float mercatorY = 0.5 * log((1.0 + sinLatitude) / (1.0 - sinLatitude));
  19. return (mercatorY - southMercatorY) * oneOverMercatorHeight;
  20. }