boost - Boost Geometry:段相交尚未实现?
问题描述
我正在尝试一个简单的测试:使用 Boost Geometry 计算 2 个段的交集。它不编译。我还尝试了一些变化(int 点而不是浮点数,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
解决方案
确实有两个问题:
您正在与 3D 几何图形相交。那没有实现相反,您可以对投影执行相同的操作。
您将“输出”几何传递给
intersects
(实际上只返回您选择的名称所intersectionExists
建议的真/假值)。在存在第三个参数的情况下,它将被用作一个策略——一个output
显然不能满足的概念。注意
intersection
总是返回 true:什么 boost::geometry::intersection 返回- 尽管这不是文档化接口的一部分
由于您的几何图形被简单地投影到 2d 平面 Z=0 上:
#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)
推荐阅读
- gcc - 如何在 dspace 生成中使用外部代码(库)?
- linux - RSS 堆栈内存分配不一致
- php - 如何自动为 nova-s3-multipart-upload 包上的视频或图像添加水印
- css - 如何自定义 Angular-Material 滑动切换
- sql - 从 SQL 获取数据 - 在 IntelliJ 中生成代码
- blazor - Blazor WASM - 错误:无法启动平台 - 部署后有时会显示一次错误
- twilio - 您尝试向您帐户上未启用的电话号码发起外拨电话
- .net - 从 Settings.settings 生成的 *.config 部分不遵守 Visual Studio XML 设置
- java - Quarkus Hibernate 找不到所需类型 [interface javax.transaction.TransactionManager] 和限定符 [[]] 的 bean
- jenkins - jenkins 下的命令“pod repo push”(使用 bigsur macstadium 节点)产生“No such file or directory xxxxxxxxxxxx REPO_NAME.podspec.json”