经纬度转为三维坐标
(2012-11-08 16:08:13)
const double EquatorRadius = 6378137.0;//赤道半径;
const double PolarRadius = 6356752.3142;//极半径;
const double Eccentricity = (EquatorRadius - PolarRadius) /
EquatorRadius;//偏心率;
const double EccentricitySquared = 2*Eccentricity -
Eccentricity*Eccentricity;//偏心率的平方;
const double LongRadius = 149600000000.0;
const double ShortRadius = 149580000000.0;
const double LSPro = LongRadius / ShortRadius;
const double Modulus = 1.0 - LSPro * LSPro;
//将经纬高转化为三维xyz,altitude海拔默认为地表海拔;
osg::Vec3d LatLonToVec(const LatAndLon& latlon,
double altitude)
{
double posX, posY, posZ;
double sin_lat = sin(osg::DegreesToRadians(latlon.latitude));
double cos_lat = cos(osg::DegreesToRadians(latlon.latitude));
double radius = EquatorRadius / sqrt(1.0 - EccentricitySquared *
sin_lat*sin_lat);
posZ = (radius * (1 - EccentricitySquared) +
altitude)*sin_lat;
posX = (radius + altitude) * cos_lat *
cos(osg::DegreesToRadians(latlon.longitude));
posY = (radius + altitude) * cos_lat *
sin(osg::DegreesToRadians(latlon.longitude));
return osg::Vec3d(posX, posY, posZ);
}
//将三维坐标转化为经纬高;
void VecToLatLon(const osg::Vec3d& vec,
LatAndLon& latlon, double&
altitude)
{
double p = sqrt(vec.x()*vec.x() + vec.y()*vec.y());
double theta = atan2(vec.z()*EquatorRadius ,
(p*PolarRadius));
double eDashSquared = (EquatorRadius*EquatorRadius -
PolarRadius*PolarRadius)/
(PolarRadius*PolarRadius);
double sin_theta = sin(theta);
double cos_theta = cos(theta);
latlon.latitude = atan( (vec.z() +
eDashSquared*PolarRadius*sin_theta*sin_theta*sin_theta) /
(p -
EccentricitySquared*EquatorRadius*cos_theta*cos_theta*cos_theta)
);
latlon.longitude = atan2(vec.y(),vec.x());
double sin_latitude = sin(latlon.latitude);
double N = EquatorRadius / sqrt( 1.0 -
EccentricitySquared*sin_latitude*sin_latitude);
altitude = p/cos(latlon.latitude) - N;
latlon.latitude = osg::RadiansToDegrees(latlon.latitude);
latlon.longitude = osg::RadiansToDegrees(latlon.longitude);
}
喜欢
0
赠金笔
加载中,请稍候......