Skip to content

Instantly share code, notes, and snippets.

@cosinekitty
Created December 5, 2019 01:52
Show Gist options
  • Save cosinekitty/6b37476d4e94271a0214d8aa604d8017 to your computer and use it in GitHub Desktop.
Save cosinekitty/6b37476d4e94271a0214d8aa604d8017 to your computer and use it in GitHub Desktop.
Function for calculating Earth radius at a specific geodetic latitude.
function EarthRadiusInMeters(latitudeRadians)
{
// latitudeRadians is geodetic, i.e. that reported by GPS.
// http://en.wikipedia.org/wiki/Earth_radius
var a = 6378137.0; // equatorial radius in meters
var b = 6356752.3; // polar radius in meters
var cos = Math.cos(latitudeRadians);
var sin = Math.sin(latitudeRadians);
var t1 = a * a * cos;
var t2 = b * b * sin;
var t3 = a * cos;
var t4 = b * sin;
return Math.sqrt((t1*t1 + t2*t2) / (t3*t3 + t4*t4));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment