Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用boost几何体旋转多边形_C++_Boost_Rotation_Boost Geometry - Fatal编程技术网

C++ 使用boost几何体旋转多边形

C++ 使用boost几何体旋转多边形,c++,boost,rotation,boost-geometry,C++,Boost,Rotation,Boost Geometry,我正在尝试使用boost geometry旋转多边形。也许我做错了什么。 我有一个多边形,不以原点为中心,声明如下: Polygon _poly; Polygon _poly2; Point2D A(4,3); Point2D B(4,5); Point2D C(6,5); Point2D D(6,3); Point2D CLOSE(4,3); _poly.outer().push_back(A); _poly.outer().push_back(B); _

我正在尝试使用boost geometry旋转多边形。也许我做错了什么。 我有一个多边形,不以原点为中心,声明如下:

Polygon _poly;
Polygon _poly2;

  Point2D A(4,3);
  Point2D B(4,5);
  Point2D C(6,5);
  Point2D D(6,3);
  Point2D CLOSE(4,3);


  _poly.outer().push_back(A);
  _poly.outer().push_back(B);
  _poly.outer().push_back(C);
  _poly.outer().push_back(D);
然后,我执行以下旋转:

  boost::geometry::strategy::transform::rotate_transformer<boost::geometry::degree, double, 2, 2> rotate(45.0);
boost::geometry::strategy::transform::rotate\u transformer rotate(45.0);
但多边形的结果坐标不正确:

多边形坐标: 4345663

旋转坐标: 40060706-2

我必须做什么?

您的多边形无效(请参阅文档)。这很容易检查
是否有效

如果您不知道输入源,可以尝试使用
boost::geometry::correct

#include <iostream>

#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/algorithms/is_valid.hpp>
#include <boost/geometry/algorithms/transform.hpp>

namespace bg  = boost::geometry;

typedef bg::model::point<double, 2, bg::cs::cartesian> Point2D;
typedef bg::model::polygon<Point2D> Polygon;
//typedef bg::model::box<Point2D> box;

int main() {

    Polygon _poly;
    Polygon _poly2;

    Point2D A(4,3);
    Point2D B(4,5);
    Point2D C(6,5);
    Point2D D(6,3);
    Point2D CLOSE(4,3);

    _poly.outer().push_back(A);
    _poly.outer().push_back(B);
    _poly.outer().push_back(C);
    _poly.outer().push_back(D);

    std::cout << std::boolalpha << bg::is_valid(_poly) << "\n";
    bg::correct(_poly);
    std::cout << std::boolalpha << bg::is_valid(_poly) << "\n";
}

在这种情况下,您显然忘记添加
闭合点

非常感谢,是的,我忘记了闭合点,因为多边形不在原点的中心
false
true