【发布时间】:2014-11-07 15:18:30
【问题描述】:
我正在尝试检查一个点是否在多边形内。为此,我想使用 boost 库。我的问题是如何修改 boost 中的示例,而不是通过 read_wkt 读取点,而是从 std 向量中读取它们。
这是来自 boost 的示例代码:
#include <iostream>
#include <list>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
int main()
{
typedef boost::geometry::model::d2::point_xy<double> point_type;
typedef boost::geometry::model::polygon<point_type> polygon_type;
polygon_type poly;
boost::geometry::read_wkt(
"POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)"
"(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", poly);
point_type p(4, 1);
std::cout << "within: " << (boost::geometry::within(p, poly) ? "yes" : "no") << std::endl;
return 0;
}
这是我的 vecPoints:
struct PNTS{
int x;
int y;
}
std::vector<PNTS> vecPoints;
请注意:我的问题不与多边形算法中的点有关。
【问题讨论】:
-
为什么不遍历你的向量并构建 WKT 字符串?这行得通吗?
-
不工作,我猜...
-
@AnasAlkhatib 将此方法添加为我的第二个答案
标签: c++ boost boost-geometry