首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >奇怪的行为使用boost::几何学::and ()来表示多边形和圆环

奇怪的行为使用boost::几何学::and ()来表示多边形和圆环
EN

Stack Overflow用户
提问于 2018-05-03 06:52:37
回答 1查看 328关注 0票数 1

我在Debian 9上开发了一个应用程序,它使用sudo apt-get install命令安装的boost-1.62.0。当我打电话给boost::geometry::with_in(polygon, ring)时,我发现了一种奇怪的行为。多边形与圆环相交,但与in不相交。以下是代码:

代码语言:javascript
复制
#include <iostream>
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/version.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/ring.hpp>
#include <boost/geometry/geometries/polygon.hpp>

using namespace std;
using namespace boost;
using namespace boost::geometry;

int main()
{
    using Point = boost::geometry::model::d2::point_xy<double>;
    using Polygon = boost::geometry::model::polygon<Point>;
    using Ring = boost::geometry::model::ring<Point>;

    Ring outer;
    append(outer, Point(-6.46720129179205, 15.61591992211971));
    append(outer, Point(-3.617204647384145, 15.61591992211971));
    append(outer, Point(-3.617204647384145, 7.615919922119708));
    append(outer, Point(-6.46720129179205, 7.615919922119708));
    append(outer, Point(-6.46720129179205, 15.61591992211971));

    Polygon polygon;
    polygon.outer() = outer;
    correct(polygon);

    Ring ring;
    append(ring, Point(-3.542202969588097, 7.615919922119709));
    append(ring, Point(-3.542202969588097, 6.81591992211971));
    append(ring, Point(-3.542202969588097, 6.015919922119708));
    append(ring, Point(-3.542202969588097, 5.215919922119708));
    append(ring, Point(-3.542202969588097, 4.415919922119708));
    append(ring, Point(-3.542202969588097, 3.615919922119708));
    append(ring, Point(-3.542202969588097, 2.815919922119709));
    append(ring, Point(-3.542202969588097, 2.015919922119709));
    append(ring, Point(-3.542202969588097, 1.215919922119709));
    append(ring, Point(-3.542202969588097, 0.4159199221197081));
    append(ring, Point(-3.542202969588097, -0.3840800778802915));
    append(ring, Point(-6.542202969588097, -0.3840800778802916));
    append(ring, Point(-6.542202969588097, 0.415919922119708));
    append(ring, Point(-6.542202969588097, 1.215919922119709));
    append(ring, Point(-6.542202969588097, 2.015919922119709));
    append(ring, Point(-6.542202969588097, 2.815919922119709));
    append(ring, Point(-6.542202969588097, 3.615919922119708));
    append(ring, Point(-6.542202969588096, 4.41591992211971));
    append(ring, Point(-6.542202969588097, 5.215919922119709));
    append(ring, Point(-6.542202969588097, 6.015919922119709));
    append(ring, Point(-6.542202969588097, 6.815919922119708));
    append(ring, Point(-6.542202969588097, 7.615919922119708));
    append(ring, Point(-3.542202969588097, 7.615919922119709));
    correct(ring);

    cout << boolalpha
         << within(polygon, ring) << endl /* should return false */
         << covered_by(polygon, ring) << endl; /* should retrurn false */

    return 0;
}

构建和运行:

代码语言:javascript
复制
 g++ -g -o wi wi.cpp
 ./wi

得到的结果:

代码语言:javascript
复制
 true
 true

多边形不是环内的,而是boost::geometry::within(polygon, ring)返回的true

所以是boost-1.62臭虫吗?以及如何修复它。

EN

回答 1

Stack Overflow用户

发布于 2018-05-03 10:18:35

差7.615919922119709 ~ 7.615919922119708为1×10^-15.

这意味着几何图形垂直重叠。根据标准的简单特性规范,这意味着它们满足within

Create solid polygon in boost geometry

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50148645

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档