简体   繁体   中英

How to rotate boost geometry around a fixed point?

I am new at using boost. I want to write a function to rotate geometry around a fixed point. I tried to boost's official example but I cannot figure out how this works because it says

Rotate rotates a geometry by a specified angle about a fixed point (eg origin)

in the official page.

Here is my code:

namespace trans = bg::strategy::transform;

point_2d p4;

trans::rotate_transformer<bg::degree, double, 2, 2> rotate(angle);
bg::transform(p, p4, rotate);

But I do not understand where to put the fixed point? or do I have to translate, rotate and translate again?

Thanks in advance.

The boost library allows for simple 2D transformation, eg translation, rotation around origin, scaling... So in your case, you'll have to express the coordinates of your point into the referential of the fixed point P (thru a translation {-xp, -yp}), then rotate it and finally express the new coordinates into the origin referential (again a translation {xp, yp}). Best regards, Arnaud

To rotate a geometry with respect to a fixed point(clockwise), you can use the matrix_transformer:

bg::strategy::transform::matrix_transformer<double, 2, 2> trans(
            cos(angle), sin(angle), x0,
           -sin(angle), cos(angle), y0,
            0,          0,          1);
boost::geometry::transform(raw, result, trans);

(x0, y0) is the coordinates of the fixed point, angle is the specified angle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM