使用 OpenCV 围绕一个点旋转一个点

2022-01-16 00:00:00 opencv point rotation c++

有谁知道如何在 OpenCV 中围绕另一个点旋转一个点?

Does anyone know how I can rotate a point around another in OpenCV?

我正在寻找这样的功能:

I am looking for a function like this:

Point2f rotatePoint(Point2f p1, Point2f center, float angle)
{
    /* MAGIC */
}

推荐答案

这些是将一个点围绕另一个点旋转一个角度 alpha 所需的步骤:

These are the steps needed to rotate a point around another point by an angle alpha:

  1. 按轴心点的负值平移该点
  2. 使用 2-d(或 3-d)旋转的标准方程旋转点
  3. 翻译回来

旋转的标准方程是:

x' = xcos(alpha) - ysin(alpha)

x' = xcos(alpha) - ysin(alpha)

y' = xsin(alpha) + ycos(alpha)

y' = xsin(alpha) + ycos(alpha)

我们以 Point(15,5) 为例,在 Point(2,2) 周围 45 度.

Let's take the example of Point(15,5) around Point(2,2) by 45 degrees.

首先,翻译:

v = (15,5) - (2,2) = (13,3)

v = (15,5) - (2,2) = (13,3)

现在旋转 45°:

v = (13*cos 45° - 3*sin 45°, 13*sin 45° + 3*cos 45°) = (7.07.., 11.31..)

v = (13*cos 45° - 3*sin 45°, 13*sin 45° + 3*cos 45°) = (7.07.., 11.31..)

最后,翻译回来:

v = v + (2,2) = (9.07.., 13.31..)

v = v + (2,2) = (9.07.., 13.31..)

注意:角度必须以弧度表示,因此将度数乘以 Pi/180

Note: Angles must be specified in radians, so multiply the number of degrees by Pi / 180

相关文章