gpt4 book ai didi

c++ - boost 、几何

转载 作者:行者123 更新时间:2023-11-30 05:41:04 26 4
gpt4 key购买 nike

我对 boost::geomentry 有疑问。

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

int main(){
typedef boost::geometry::model::d2::point_xy<double> TBoostPoint;
typedef boost::geometry::model::polygon<TBoostPoint> TBoostPoly;
TBoostPoly square, square1;
square.outer().push_back(TBoostPoint(0.5,4.25));
square.outer().push_back(TBoostPoint(0.5,4.5));
square.outer().push_back(TBoostPoint(1.0,4.5));
square.outer().push_back(TBoostPoint(1.0,4.25));
square.outer().push_back(TBoostPoint(0.5,4.25));
const double eps[] = {1e-15,1e-15,2e-15,2e-15};
square.outer().push_back(TBoostPoint(0.5,4.25 + eps[0]));
square.outer().push_back(TBoostPoint(0.5,4.5 + eps[1]));
square.outer().push_back(TBoostPoint(1.0,4.5 + eps[2]));
square.outer().push_back(TBoostPoint(1.0,4.25 + eps[3]));
square.outer().push_back(TBoostPoint(0.5,4.25 + eps[0]));
boost::geometry::correct(square);
boost::geometry::correct(square1);
std::vector<TBoostPoly> output;
boost::geometry::intersection(square,square1,output);
return 0;
}

如果我使用 Boost(1_58) 输出 - 不正确,但如果我使用 Boost(1_551_52),输出 -是正确的。



预期

{(0.5,4.25),(0.5,4.5),(1.0,4.25),(1.0,4.25),(0.5,4.25)}

结果( boost 1_58)

{(0.5,4.25),(0.5,4.5),(1.0,4.25),(1.0,4.25 + 5e-8),(0.5,4.25)}.

最佳答案

你必须使用积分坐标。

来自文档:http://www.boost.org/doc/libs/1_58_0/libs/polygon/doc/index.htm

The coordinate data type is a template parameter of all data types and algorithms provided by the library, and is expected to be integral. Floating point coordinate data types are not supported by the algorithms implemented in the library due to the fact that the achieving floating point robustness implies a different set of algorithms and generally platform specific assumptions about floating point representations.

同样适用于早期版本。

在您的情况下,Boost(1_55 或 1_52) 的输出是正确的(偶然)。

关于c++ - boost 、几何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31298060/

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