I am trying to rotate a polygon using boost geometry. Probably I am doing something wrong. I have a polygon, not centered in the origin, declared like this:
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);
Then, I perform a rotation with:
boost::geometry::strategy::transform::rotate_transformer<boost::geometry::degree, double, 2, 2> rotate(45.0);
But the resulting coordinates of the polygon are not the correct ones:
poly's coordinates: 4 3 4 5 6 5 6 3
rotated coordinates: 4 0 6 0 7 0 6 -2
What I have to do?
You polygon is invalid (see the documentation). This is easy to check with
is_valid
.If you don't know the input source, you can always try to correct with
boost::geometry::correct
:Live On Coliru
Output:
In this case you clearly forgot to add the
CLOSE
point