Boost Geometry:段相交尚未实现?

Boost Geometry: segments intersection not yet implemented?

我正在尝试一个简单的测试:使用 Boost Geometry 计算 2 个线段的交集。它不编译。我也尝试了一些变化(整数点而不是浮点数,2D 而不是 3D),但没有任何改进。

boost真的有可能不实现段交集吗?或者我做错了什么?缺少一些 hpp ? 算法“相交”和“相交”之间的混淆?

代码非常基础:

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/segment.hpp>
#include <boost/geometry/algorithms/intersection.hpp>

    typedef boost::geometry::model::point<float, 3, boost::geometry::cs::cartesian> testPoint;
    typedef boost::geometry::model::segment<testPoint> testSegment;

    testSegment s1(
        testPoint(-1.f, 0.f, 0.f),
        testPoint(1.f, 0.f, 0.f)
    );
    testSegment s2(
        testPoint(0.f, -1.f, 0.f),
        testPoint(0.f, 1.f, 0.f)
    );
    std::vector<testPoint> output;
    bool intersectionExists = boost::geometry::intersects(s1, s2, output);

但是我在Visual编译时得到了以下错误:

- Error C2039   'apply' n'est pas membre de 'boost::geometry::dispatch::disjoint<Geometry1,Geometry2,3,boost::geometry::segment_tag,boost::geometry::segment_tag,false>'    CDCadwork   C:\Program Files\Boost\boost_1_75_0\boost\geometry\algorithms\detail\disjoint\interface.hpp 54  
- Error C2338   This operation is not or not yet implemented.   CDCadwork   C:\Program Files\Boost\boost_1_75_0\boost\geometry\algorithms\not_implemented.hpp   47  

确实有两个问题:

  1. 您正在与 3D 几何图形相交。那没有实现 相反,您可以对投影执行相同的操作。

  2. 您正在将“输出”几何传递给 intersects(实际上只有 returns true/false 值作为您选择的名称 intersectionExists建议)。在存在第三个参数的情况下,它将用作策略 - output 显然不满足的概念。

    Note intersection always returns true: - although that's not part of the documented interface

由于您的几何图形被平凡地投影到二维平面 Z=0:

Live On Coliru

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/segment.hpp>
#include <iostream>

namespace bg = boost::geometry;
namespace bgm = bg::model;

using Point   = bgm::point<float, 2, bg::cs::cartesian>;
using Segment = bgm::segment<Point>;

int main() {
    Segment s1{{-1, 0}, {1, 0}};
    Segment s2{{0, -1}, {0, 1}};

    bool exists = bg::intersects(s1, s2);

    std::vector<Point> output;
    /*bool alwaysTrue = */ bg::intersection(s1, s2, output);

    std::cout << bg::wkt(s1) << "\n";
    std::cout << bg::wkt(s2) << "\n";
    for (auto& p : output) {
        std::cout << bg::wkt(p) << "\n";
    }

    return exists? 0:1;
}

版画

LINESTRING(-1 0,1 0)
LINESTRING(0 -1,0 1)
POINT(0 0)