gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:21:09 28 4
gpt4 key购买 nike

我最近尝试在 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/

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