我有一个像这样的旋转矩阵:
1.0 0.0 0.0 2.07814
0.0 -0.809017 0.587785 0.0
0.0 -0.587785 -0.809017 0.0
0.0 0.0 0.0 1.0
Run Code Online (Sandbox Code Playgroud)
我如何从中获得角度?如果我应用逆,我得到这个
cos exp -1 (-0.809017) = 144.0
sin exp -1 (-0.587785) = -36.0
sin exp -1 ( 0.587785) = 36.0
cos exp -1 (-0.809017) = 144.0
Run Code Online (Sandbox Code Playgroud)
但我的问题是我知道角度是216.0度,我该如何回到那个角度?
要从3x3旋转矩阵(R)获得旋转角度(θ),您可以使用以下公式:
tr(R)= 1 + 2*cos(theta),
其中tr是迹线.
在您的示例中,旋转由下式给出:
1.00000 0.00000 0.00000
0.00000 -0.80902 0.58779
0.00000 -0.58779 -0.80902
Run Code Online (Sandbox Code Playgroud)
因此,痕迹是
1 - 0.80902 - 0.80902 = -0.61804`
Run Code Online (Sandbox Code Playgroud)
角度为acos(( - 0.61804-1)/ 2)*(180/pi)= 144°
因此,矩阵表示逆时针旋转144°.或者,当144 = -216 mod 360时,它表示顺时针旋转216°.
我认为你正在计算反函数 不正确以一种让我感到奇怪的方式.你应该使用asin逆sin和acos逆cos.你正在计算乘法逆,而不是函数逆.虽然在这里看起来是一回事.
使用该atan2()功能.它将从y和x值产生角度.它隐含地计算逆sin和逆cos,并检查y和x的符号以发现正确的象限.
ATAN2(3)
NAME
1.8 `atan2', `atan2f'--arc tangent of y/x
SYNOPSIS
#include
double atan2(double Y,double X);
float atan2f(float Y,float X);
DESCRIPTION
`atan2' computes the inverse tangent (arc tangent) of Y/X. `atan2'
produces the correct result even for angles near pi/2 or -pi/2 (that
is, when X is near 0).
`atan2f' is identical to `atan2', save that it takes and returns `float'.
RETURNS
`atan2' and `atan2f' return a value in radians, in the range of -pi to pi.
我假设我们忽略了2.07814,这显然不是轮换的一部分.atan2(0.587785, -0.809017)给我144.0度.atan(-0.587785, -0.809017)给出216.0.
1 0 0
0 cos sin
0 -sin cos
Run Code Online (Sandbox Code Playgroud)
......让我像以前一样困惑.我一直得到144.0.
坦白.
我忽略了上面的弧度/度问题,因为我使用的是Postscript而不是C.
$ gsnd -q
GS>0.587785 -0.809017 atan =
144.0
GS>-0.587785 -0.809017 atan =
216.0
GS>
Run Code Online (Sandbox Code Playgroud)