c++根据两点经纬度坐标获取长度

#define PI 3.141592657
#define EARTH_RADIUS  6378137
static inline double  rad( double degree )
{
    return  PI * degree / 180.0;
}
static inline double haverSin(double x)
{
    double v = sin(x / 2.0);
    return v * v;
}
//计算距离(单位 : m)
static double getDistance(double lon1, double lat1, double lon2, double lat2)
{
    double radlon1 = rad(lon1);
    double radlat1 = rad(lat1);
    double radlon2 = rad(lon2);
    double radlat2 = rad(lat2);
    
    double a = fabs(radlat1 - radlat2);
    double b = fabs(radlon1 - radlon2);
    
    double h = haverSin(b) + cos(lat1)*cos(lat2)*haverSin(a);
    double distance = 2 * EARTH_RADIUS * asin(sqrt(h));
    return  distance;
}

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是使用osgEarth 2.10获取给定经纬度坐标的高程信息的C++代码示例: ```cpp #include <osgEarth/Map> #include <osgEarth/MapNode> #include <osgEarthUtil/ElevationQuery> #include <osgEarthUtil/EarthManipulator> osg::ref_ptr<osgEarth::MapNode> createMapNode() { // 创建一个空的地图 osg::ref_ptr<osgEarth::Map> map = new osgEarth::Map(); // 创建一个地形图层 osgEarth::Drivers::SimpleOceanLayerFactory oceanFactory; osg::ref_ptr<osgEarth::Layer> oceanLayer = oceanFactory.create(map.get(), nullptr); map->addLayer(oceanLayer.get()); // 创建一个工具层 osgEarth::Drivers::SimpleElevationLayerFactory elevationFactory; osg::ref_ptr<osgEarth::Layer> elevationLayer = elevationFactory.create(map.get(), nullptr); map->addLayer(elevationLayer.get()); // 创建地图节点 osgEarth::MapNodeOptions options; options.map() = map.get(); return new osgEarth::MapNode(options); } double getElevation(double latitude, double longitude) { // 创建地图节点 osg::ref_ptr<osgEarth::MapNode> mapNode = createMapNode(); // 创建高程查询对象 osg::ref_ptr<osgEarth::Util::ElevationQuery> elevationQuery = new osgEarth::Util::ElevationQuery(mapNode.get()); // 设置查询的经纬度坐标 osgEarth::GeoPoint point( mapNode->getMapSRS(), osgEarth::Units::DEGREES, longitude, latitude); elevationQuery->setPoint(point); // 执行高程查询 osgEarth::Util::ElevationQuery::QueryResult result; if (elevationQuery->getQuery(result)) { return result.elevation().as(osgEarth::Units::METERS); } else { // 查询失败 return 0.0; } } int main() { double latitude = 40.7128; // 纬度 double longitude = -74.0060; // 经度 double elevation = getElevation(latitude, longitude); std::cout << "Elevation at (" << latitude << ", " << longitude << "): " << elevation << " meters" << std::endl; return 0; } ``` 以上代码利用osgEarth库获取给定经纬度坐标的高程信息。需要注意的是,你需要正确配置osgEarth库及其依赖,并将相关头文件和库文件链接到你的项目中。此外,你也需要使用合适的地形图层数据来获得准确的高程信息。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值