osgEarth 2.1.1
|
Static Public Member Functions | |
static double | distance (double lat1Rad, double lon1Rad, double lat2Rad, double lon2Rad, double radius=osg::WGS_84_RADIUS_EQUATOR) |
static double | distance (const std::vector< osg::Vec3d > &points, double radius=osg::WGS_84_RADIUS_EQUATOR) |
static double | distance (const osg::Vec3d &p1, const osg::Vec3d &p2, const SpatialReference *srs) |
static double | bearing (double lat1Rad, double lon1Rad, double lat2Rad, double lon2Rad) |
static void | midpoint (double lat1Rad, double lon1Rad, double lat2Rad, double lon2Rad, double &out_latRad, double &out_lonRad) |
static void | destination (double lat1Rad, double lon1Rad, double bearingRad, double distance, double &out_latRad, double &out_lonRad, double radius=osg::WGS_84_RADIUS_EQUATOR) |
static double | rhumbDistance (double lat1Rad, double lon1Rad, double lat2Rad, double lon2Rad, double radius=osg::WGS_84_RADIUS_EQUATOR) |
static double | rhumbDistance (const std::vector< osg::Vec3d > &points, double radius=osg::WGS_84_RADIUS_EQUATOR) |
static double | rhumbBearing (double lat1Rad, double lon1Rad, double lat2Rad, double lon2Rad) |
static void | rhumbDestination (double lat1Rad, double lon1Rad, double bearing, double distance, double &out_latRad, double &out_lonRad, double radius=osg::WGS_84_RADIUS_EQUATOR) |
Useful calculations for lat/long points. Converted from http://www.movable-type.co.uk/scripts/latlong.html
double GeoMath::bearing | ( | double | lat1Rad, |
double | lon1Rad, | ||
double | lat2Rad, | ||
double | lon2Rad | ||
) | [static] |
Computes the initial bearing from one point to the next in radians
lat1Rad | The start latitude in radians |
lon1Rad | The start longitude in radians |
lat2Rad | The end latitude in radians |
lon2Rad | The end longitude in radians |
Definition at line 72 of file GeoMath.cpp.
{ double dLon = (lon2Rad-lon1Rad); double y = sin(dLon) * cos(lat2Rad); double x = cos(lat1Rad)*sin(lat2Rad) - sin(lat1Rad)*cos(lat2Rad)*cos(dLon); double brng = atan2(y, x); return brng; }
void GeoMath::destination | ( | double | lat1Rad, |
double | lon1Rad, | ||
double | bearingRad, | ||
double | distance, | ||
double & | out_latRad, | ||
double & | out_lonRad, | ||
double | radius = osg::WGS_84_RADIUS_EQUATOR |
||
) | [static] |
Computes the destination point given a start point, a bearing and a distance
lat1Rad | The latitude in radians |
lon1Rad | The longitude in radians |
bearingRad | The bearing in radians |
distance | The distance in meters |
out_latRad | The destination point's latitude in radians |
out_lonRad | The destination points' longitude in radians |
radius | The radius of the earth in meters |
Definition at line 103 of file GeoMath.cpp.
{ double dR = distance / radius; out_latRad = asin( sin(lat1Rad)*cos(dR) + cos(lat1Rad)*sin(dR)*cos(bearingRad) ); out_lonRad = lon1Rad + atan2(sin(bearingRad)*sin(dR)*cos(lat1Rad), cos(dR)-sin(lat1Rad)*sin(out_latRad)); }
double GeoMath::distance | ( | double | lat1Rad, |
double | lon1Rad, | ||
double | lat2Rad, | ||
double | lon2Rad, | ||
double | radius = osg::WGS_84_RADIUS_EQUATOR |
||
) | [static] |
Computes the distance between the given points in meters using the Haversine formula
lat1Rad | The start latitude in radians |
lon1Rad | The start longitude in radians |
lat2Rad | The end latitude in radians |
lon2Rad | The end longitude in radians |
radius | The radius of the earth in meters |
Definition at line 25 of file GeoMath.cpp.
{ double dLat = (lat2Rad-lat1Rad); double dLon = (lon2Rad-lon1Rad); double a = sin(dLat/2.0) * sin(dLat/2.0) + cos(lat1Rad) * cos(lat2Rad) * sin(dLon/2.0) * sin(dLon/2.0); double c = 2.0 * atan2(sqrt(a), sqrt(1.0-a)); double d = radius * c; return d; }
double GeoMath::distance | ( | const std::vector< osg::Vec3d > & | points, |
double | radius = osg::WGS_84_RADIUS_EQUATOR |
||
) | [static] |
Computes the distance covered by the given path in meters using the Haversine formula Assumes the points in Lon, Lat in degrees
Definition at line 38 of file GeoMath.cpp.
{ double length = 0; if (points.size() > 1) { for (unsigned int i = 0; i < points.size()-1; ++i) { const osg::Vec3d& current = points[i]; const osg::Vec3d& next = points[i+1]; length += GeoMath::distance(osg::DegreesToRadians(current.y()), osg::DegreesToRadians(current.x()), osg::DegreesToRadians(next.y()), osg::DegreesToRadians(next.x()), radius); } } return length; }
double GeoMath::distance | ( | const osg::Vec3d & | p1, |
const osg::Vec3d & | p2, | ||
const SpatialReference * | srs | ||
) | [static] |
Computes the distance between two points, in meters.
Definition at line 56 of file GeoMath.cpp.
{ if ( srs == 0L || srs->isProjected() ) { return (p2-p1).length(); } else { return distance( osg::DegreesToRadians( p1.y() ), osg::DegreesToRadians( p1.x() ), osg::DegreesToRadians( p2.y() ), osg::DegreesToRadians( p2.x() ), srs->getEllipsoid()->getRadiusEquator() ); } }
void GeoMath::midpoint | ( | double | lat1Rad, |
double | lon1Rad, | ||
double | lat2Rad, | ||
double | lon2Rad, | ||
double & | out_latRad, | ||
double & | out_lonRad | ||
) | [static] |
Computes the midpoint between two points
lat1Rad | The start latitude in radians |
lon1Rad | The start longitude in radians |
lat2Rad | The end latitude in radians |
lon2Rad | The end longitude in radians |
out_latRad | The latitude of the midpoint in radians |
out_lonRad | The longitude of the midpoint in radians |
Definition at line 83 of file GeoMath.cpp.
{ double dLon = (lon2Rad-lon1Rad); double cosLat1 = cos(lat1Rad); double cosLat2 = cos(lat2Rad); double sinLat1 = sin(lat1Rad); double sinLat2 = sin(lat2Rad); double Bx = cosLat2 * cos(dLon); double By = cosLat2 * sin(dLon); out_latRad = atan2(sinLat1+sinLat2, sqrt( (cosLat1+Bx)*(cosLat1+Bx) + By*By) ); out_lonRad = lon1Rad + atan2(By, cosLat1 + Bx); }
double GeoMath::rhumbBearing | ( | double | lat1Rad, |
double | lon1Rad, | ||
double | lat2Rad, | ||
double | lon2Rad | ||
) | [static] |
Computes the bearing of the rhumb line between two points in radians
lat1Rad | The start latitude in radians |
lon1Rad | The start longitude in radians |
lat2Rad | The end latitude in radians |
lon2Rad | The end longitude in radians |
Definition at line 150 of file GeoMath.cpp.
{ double dLon = lon2Rad - lon1Rad; double dPhi = log(tan(lat2Rad/2.0+osg::PI/4.0)/tan(lat1Rad/2.0+osg::PI/4.0)); if (osg::absolute(dLon) > osg::PI) dLon = dLon > 0.0 ? -(2.0*osg::PI-dLon) : (2.0*osg::PI+dLon); double brng = atan2(dLon, dPhi); return fmod(brng + 2.0 * osg::PI, 2.0 * osg::PI); }
void GeoMath::rhumbDestination | ( | double | lat1Rad, |
double | lon1Rad, | ||
double | bearing, | ||
double | distance, | ||
double & | out_latRad, | ||
double & | out_lonRad, | ||
double | radius = osg::WGS_84_RADIUS_EQUATOR |
||
) | [static] |
Computes the destination point given a start point, a bearing and a distance along a rhumb line
lat1Rad | The latitude in radians |
lon1Rad | The longitude in radians |
bearingRad | The bearing in radians |
distance | The distance in meters |
out_latRad | The destination point's latitude in radians |
out_lonRad | The destination points' longitude in radians |
radius | The radius of the earth in meters |
Definition at line 163 of file GeoMath.cpp.
{ double R = radius; double d = distance / R; double lat2Rad = lat1Rad + d*cos(bearing); double dLat = lat2Rad-lat1Rad; double dPhi = log(tan(lat2Rad/2.0+osg::PI/4.0)/tan(lat1Rad/2.0+osg::PI/4.0)); double q = (!osg::isNaN(dLat/dPhi)) ? dLat/dPhi : cos(lat1Rad); // E-W line gives dPhi=0 double dLon = d*sin(bearing)/q; // check for some daft bugger going past the pole if (osg::absolute(lat2Rad) > osg::PI/2.0) lat2Rad = lat2Rad > 0.0 ? osg::PI-lat2Rad : -(osg::PI-lat2Rad); //double lon2Rad = (lon1Rad+dLon+3.0*Math.PI)%(2.0*osg::PI) - osg::PI; double lon2Rad = fmod((lon1Rad+dLon+3.0*osg::PI),(2.0*osg::PI)) - osg::PI; out_latRad = lat2Rad; out_lonRad = lon2Rad; }
double GeoMath::rhumbDistance | ( | double | lat1Rad, |
double | lon1Rad, | ||
double | lat2Rad, | ||
double | lon2Rad, | ||
double | radius = osg::WGS_84_RADIUS_EQUATOR |
||
) | [static] |
Computes the distance between two points in meters following a rhumb line
lat1Rad | The start latitude in radians |
lon1Rad | The start longitude in radians |
lat2Rad | The end latitude in radians |
lon2Rad | The end longitude in radians |
radius | The radius of the earth in meters |
Definition at line 117 of file GeoMath.cpp.
{ double dLat = (lat2Rad - lat1Rad); double dLon = osg::absolute(lon2Rad - lon1Rad); double dPhi = log(tan(lat2Rad/2.0+osg::PI/4.0)/tan(lat1Rad/2.0+osg::PI/4.0)); double q = (!osg::isNaN(dLat/dPhi)) ? dLat/dPhi : cos(lat1Rad); // E-W line gives dPhi=0 // if dLon over 180° take shorter rhumb across 180° meridian: if (dLon > osg::PI) dLon = 2.0*osg::PI - dLon; double dist = sqrt(dLat*dLat + q*q*dLon*dLon) * radius; return dist; }
double GeoMath::rhumbDistance | ( | const std::vector< osg::Vec3d > & | points, |
double | radius = osg::WGS_84_RADIUS_EQUATOR |
||
) | [static] |
Computes the distance between two points in meters following a rhumb line Assumes the points are in Lon, Lat in degrees
Definition at line 133 of file GeoMath.cpp.
{ double length = 0; if (points.size() > 1) { for (unsigned int i = 0; i < points.size()-1; ++i) { const osg::Vec3d& current = points[i]; const osg::Vec3d& next = points[i+1]; length += GeoMath::rhumbDistance(osg::DegreesToRadians(current.y()), osg::DegreesToRadians(current.x()), osg::DegreesToRadians(next.y()), osg::DegreesToRadians(next.x()), radius); } } return length; }