加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

经纬度转为三维坐标

(2012-11-08 16:08:13)
标签:

经纬坐标转换

分类: osg

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

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有