gpt4 book ai didi

c++ - boost 路口

转载 作者:行者123 更新时间:2023-11-30 03:55:22 26 4
gpt4 key购买 nike

我对 boost 交集算法有疑问。我不确定是我做错了还是错误。

#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>
int main()
{
typedef boost::geometry::model::d2::point_xy<double> BoostPointXY;
typedef boost::geometry::model::polygon<BoostPointXY> BoostPolygon;

BoostPolygon polyOne, polyTwo;
boost::geometry::read_wkt(
"POLYGON((45, 4), (45, 17), (44, 19), (44, 22), (50, 20), (51.5, 17), (58, 4), (60, 0), (53, 0), (45, 0), (45, 4))",
polyOne);
boost::geometry::read_wkt(
"POLYGON((-10, -5), (0, 25), (43, 25), (45, 20), (50, 20), (60, 0), (5, 0), (5, -5), (-10, -5))", polyTwo);
std::vector<BoostPolygon> multiPoly;
boost::geometry::correct(polyOne);
boost::geometry::correct(polyTwo);
boost::geometry::intersection(polyOne,polyTwo,multiPoly);
std::cout << "Size of Multi " << multiPoly.size() << std::endl;
std::cout << "Using Boost "
<< BOOST_VERSION / 100000 << "." // major version
<< BOOST_VERSION / 100 % 1000 << "." // minior version
<< BOOST_VERSION % 100 // patch level
<< std::endl;
}

输出:

Size of Multi 0
Using Boost 1.55.0

但是multiPolygon的大小应该是1还是?当它是一个错误时,有人可以用当前的 boost 1.57 测试它吗?我目前无法更改我的 boost 版本。

谢谢

最佳答案

您的 WKT 数据无效:

boost::geometry::read_wkt("POLYGON((45  4, 45  17, 44  19, 44  22, 50  20, 51.5  17, 58  4, 60  0, 53  0, 45  0, 45  4))", polyOne);
boost::geometry::read_wkt("POLYGON((-10 -5, 0 25, 43 25, 45 20, 50 20, 60 0, 5 0, 5 -5, -10 -5))", polyTwo);

您的样本只是使用了许多无效的(?)内环。

现在你得到:

Size of Multi 1

enter image description here

Live On Coliru

#include <boost/geometry.hpp>
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/ring.hpp>
#include <boost/geometry/io/io.hpp>
#include <fstream>
#include <iostream>

int main() {
typedef boost::geometry::model::d2::point_xy<double> BoostPointXY;
typedef boost::geometry::model::polygon<BoostPointXY> BoostPolygon;

BoostPolygon polyOne, polyTwo;
boost::geometry::read_wkt("POLYGON((45 4, 45 17, 44 19, 44 22, 50 20, 51.5 17, 58 4, 60 0, 53 0, 45 0, 45 4))", polyOne);
boost::geometry::read_wkt("POLYGON((-10 -5, 0 25, 43 25, 45 20, 50 20, 60 0, 5 0, 5 -5, -10 -5))", polyTwo);

boost::geometry::correct(polyOne);
boost::geometry::correct(polyTwo);

{
std::ofstream svg("/tmp/svg.svg");
boost::geometry::svg_mapper<BoostPointXY> mapper(svg, 400, 400);
mapper.add(polyOne);
mapper.add(polyTwo);

mapper.map(polyOne, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2");
mapper.map(polyTwo, "fill-opacity:0.5;fill:rgb(204,153,0);stroke:rgb(204,153,0);stroke-width:2");
}

std::vector<BoostPolygon> multiPoly;
boost::geometry::intersection(polyOne,polyTwo,multiPoly);
std::cout << "Size of Multi " << multiPoly.size() << std::endl;
}

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

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