简体   繁体   English

如何围绕固定点旋转增强几何?

[英]How to rotate boost geometry around a fixed point?

I am new at using boost.我是使用 boost 的新手。 I want to write a function to rotate geometry around a fixed point.我想写一个 function 来围绕一个固定点旋转几何。 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) Rotate 将几何图形围绕固定点(例如原点)旋转指定角度

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}). boost库允许简单的2D转换,例如平移,围绕原点旋转,缩放......所以在你的情况下,你必须将你的点的坐标表达为固定点P的参考(通过翻译{- xp, -yp}),然后旋转它,最后将新坐标表示为原点参考(再次是平移 {xp, yp})。 Best regards, Arnaud最好的问候, 阿诺

To rotate a geometry with respect to a fixed point(clockwise), you can use the matrix_transformer:要相对于固定点(顺时针)旋转几何图形,可以使用 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. (x0, y0) 是固定点的坐标,angle 是指定的角度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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