c++ - boost 、几何

标签 c++ boost intersection boost-geometry

我对 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/

相关文章:

java - 在 Java 中查找 N 个列表之间的公共(public)元素

nhibernate - NHibernate交集

python - 有没有办法在Python中获取元组或列表的差异和交集?

c++ - 我对 N4140 中 [basic.link]/7 的理解是否正确?

C++ 更快的字符串解析?

c++ - ld : symbol(s) not found for architecture x86_64 (Xcode 4)//opengles. o

c++ - boost shared_ptr use_count 函数

c++ - boost::iostreams 管理资源

C++ 转换会创建一个新对象吗?

c++ - vector 图,坏访问器