首先,为了简单起见,您需要将 AB 的任何运动表示为围绕单个点的旋转和平移,例如点 A。然后,对于需要与 AB 一起旋转的任何其他点,您应该通过减去点 A 将该点移动到线 AB 的空间中,然后通过在平移后将新点 A 添加回它来将其转换回世界空间和旋转。
我手头没有公式,但我会尝试挖掘一个例子。
编辑
未经测试的代码:
void transform_points(const point2f ¢er, vector<point2f> &points, const point2f &offset, float angle)
{
// transform points into a space where 'center' is the origin
mat3f to_origin = mat3f(1, 0, -center.x,
0, 1, -center.y,
0, 0, 1);
// rotate the points around the origin
mat3f rot = mat3f(cos(angle), -sin(angle), 0,
sin(angle), cos(angle), 0,
0, 0, 1);
// move the points back into world space
mat3f to_world = mat3f(1, 0, center.x,
0, 1, center.y,
0, 0, 1);
// offset the points by 'offset'
mat3f off = mat3f(1, 0, offset.x,
0, 1, offset.y,
0, 0, 1);
// concatenate all transformations for efficiency
mat3f xform = off * to_world * rot * to_origin;
// this loop could be parallelized using SIMD or multiple cores
for(auto &p : points)
p = xform * p;
}