gpt4 book ai didi

c++ - 球体 line_interpolate - 但在另一个方向

转载 作者:行者123 更新时间:2023-12-05 04:31:04 25 4
gpt4 key购买 nike

boost::geometry::line_interpolateboost::geometry::srs::spheroid 结合使用,我正在计算沿最短距离的大圆导航点2个地理点。下面的代码计算围绕大圆的最短距离的导航点。在极少数情况下,我需要生成以错误方向环绕地球的较长距离。例如,当在 (20, 20) 和 (30, 20) 的经/纬度之间插值时,较短方向只有 10 度的差异,而另一个方向有 350 度的差异。在某些情况下,我希望能够在较长的方向(例如 350 度)进行插值。

这张 2d map 以红色显示 10 度经度差异,以绿色显示 350 度经度差异。我用手画了绿线,这条线只是一个近似值。 如何获得这条绿线的积分?

20,20 to 20,30 map

此代码基于来自 boost.org 的示例,line_interpolate_4_with_strategy

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

int main()
{
typedef boost::geometry::model::d2::point_xy<double, boost::geometry::cs::geographic<boost::geometry::degree> > Point_Type;
using Segment_Type = boost::geometry::model::segment<Point_Type>;
using Multipoint_Type = boost::geometry::model::multi_point<Point_Type>;


boost::geometry::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
boost::geometry::strategy::line_interpolate::geographic<boost::geometry::strategy::vincenty> str(spheroid);


Segment_Type const start_end_points { {20, 20}, {30, 20} }; // lon/lat, interpolate between these two points
double distance { 50000 }; // plot a point ever 50km
Multipoint_Type mp;
boost::geometry::line_interpolate(start_end_points, distance, mp, str);
std::cout << "on segment : " << wkt(mp) << "\n";

return 0;
}

最佳答案

请注意,line_interpolate 在线串上插入点,其中两点之间的线段遵循 geodesic .

因此,一种解决方法是创建一个指向原始线段质心的对映点,并创建一个遵循请求路径的线串。然后使用此线串调用 line_interpolate。以下代码可以解决问题。

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

int main()
{
namespace bg = boost::geometry;
using Point_Type = bg::model::d2::point_xy<double, bg::cs::geographic<bg::degree>>;
using Segment_Type = boost::geometry::model::segment<Point_Type>;
using Linstring_Type = bg::model::linestring<Point_Type>;
using Multipoint_Type = bg::model::multi_point<Point_Type>;

bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
bg::strategy::line_interpolate::geographic<bg::strategy::vincenty> str(spheroid);

Segment_Type const start_end_points { {20, 20}, {30, 20} };

Point_Type centroid;
bg::centroid(start_end_points, centroid);

Point_Type antipodal_centroid;
bg::set<0>(antipodal_centroid, bg::get<0>(centroid) + 180);
bg::set<1>(antipodal_centroid, bg::get<1>(centroid) * -1);

Linstring_Type line;
line.push_back(start_end_points.first);
line.push_back(antipodal_centroid);
line.push_back(start_end_points.second);

double distance { 50000 }; // plot a point ever 50km
Multipoint_Type mp;
bg::line_interpolate(line, distance, mp, str);
std::cout << "on segment : " << wkt(mp) << "\n";

return 0;
}

结果是这样的: world_interpolation

请注意,由于您正在构建的椭球体是非球形的,因此没有大圆(除了赤道和子午线)并且测地线段未闭合但看起来像 this .因此,您会注意到最后一个插值点将不同于线段的端点。

关于c++ - 球体 line_interpolate - 但在另一个方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71925038/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com