c++ - 检查boost中的多边形特征

标签 c++ boost boost-geometry

我最近尝试开发 boost::geometry 库。我找到了下面的代码

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/polygon.hpp>

#include <iostream>

namespace bg = boost::geometry;

int main(void)
{
    typedef bg::model::point<double, 2, bg::cs::cartesian> point;
    typedef bg::model::polygon<point> polygon;

    //! create a polygon
    polygon p;
    p.outer().push_back(point(0., 0.));
    p.outer().push_back(point(1., 0.));
    p.outer().push_back(point(1., 2.));
    p.outer().push_back(point(2., 3.));
    p.outer().push_back(point(0., 4.));

    //! display it
    std::cout << "generated polygon:" << std::endl;
    std::cout << bg::wkt<polygon>(p) << std::endl;

    return 0;
}

任何检查的想法:

  1. 它是一个简单的多边形吗?
  2. 方向是什么(顺时针、逆时针)
  3. 关门了吗?

顺便说一下,我使用的是boost版本1.53.0。

最佳答案

Polygon的概念BG 中解释了大多数高层决策:

A polygon is A polygon is a planar surface defined by one exterior boundary and zero or more interior boundaries (OGC Simple Feature Specification).

So the definition of a Boost.Geometry polygon differs a bit from e.g. Wiki, where a polygon does not have holes. A polygon of Boost.Geometry is a polygon with or without holes. (A polygon without holes is a helper geometry within Boost.Geometry, and referred to as a ring.)

Ring我们发现:

  • there might be a specialization of traits::point_order defining the order or orientation of its points, clockwise or counterclockwise
  • there might be a specialization of traits::closure defining the closure, open or closed

规则下,您可以找到问题的大部分答案:

Besides the Concepts, which are checks on compile-time, there are some other rules that valid polygons must fulfill. This follows the opengeospatial rules (see link above).

  • Polygons are simple geometric objects (See also wiki but holes are allowed in Boost.Geometry polygons).
  • If the polygons underlying ring_type is defined as clockwise, the exterior ring must have the clockwise orientation, and any interior ring must be reversed w.r.t. the defined orientation (so: counter clockwise for clockwise exterior rings). If the ring_type is defined counter clockwise, it is vice versa.
  • If the polygons underlying ring_type is defined as closed, all rings must be closed: the first point must be spatially equal to the last point.
  • The interior is a connected point set.
  • There should be no self intersections, but self tangencies (between exterior/interior rings) are allowed (as long as the interior is a connected point set.
  • There should be no cut lines, spikes or punctures.
  • The interior rings should be located within the exterior ring. Interior rings may not be located within each other.

请注意

  1. 您可以使用boost::geometry::correct 纠正不符合上述所有要求的环/多边形。
  2. 添加了 Boost 1.56.0 boost::geometry::is_valid 这样您就可以验证几何图形的有效性。对于旧版本,请参阅例如<强> polygons union using boost

关于c++ - 检查boost中的多边形特征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26161076/

相关文章:

c++ - 错误 WinSock.h 已包含 Boost Windows Qt

c++ - 使用增强几何适应几何对象模型的问题

c++ - 如何组合两个 Boost Geometry 变压器?

c++ - 如何在 boost 中填充多边形?

c++ - 打印: Displaying an SHA1 hash in hexadecimal

C++ 错误 STATUS_ACCESS_VIOLATION

c++ - 如何在自己的方法中使用 lambda 表达式

c++ - 使用 C++ 在 DLL 中进行子类化

c++ - boost::copy_graph 的vertex_copy 是如何工作的?

c++ - 线程安全设置