我希望找到旋转矩阵,以获得三个(几乎)正交向量,它们位于世界坐标系的同一方向
我的三个(几乎)正交向量可以用python表示如下:
vectors = np.array([[ 0.43187079, 0.90161148, 0.02417362],
[-0.46076794, 0.19750816, 0.86526495],
[ 0.77535832, -0.38482109, 0.50073167]])
我当前使用的代码可以使向量与世界坐标平行,但方向不正确。运行此代码
xrotation = np.arctan2(vectors[2, 1], vectors[2, 2])
xRot = np.array([[1, 0, 0],
[0, np.cos(xrotation), -np.sin(xrotation)],
[0, np.sin(xrotation), np.cos(xrotation)]])
vectors_x = np.zeros((3, 3))
for i in range(3):
vectors_x[i, :] = np.linalg.inv(xRot.transpose()) @ vectors[i, :]
yrotation = np.arctan2(vectors_x[1, 2], vectors_x[1, 0])
yRot = np.array([[np.cos(yrotation), 0, np.sin(yrotation)],
[0, 1, 0],
[-np.sin(yrotation), 0, np.cos(yrotation)]])
vectors_y = np.zeros((3, 3))
for i in range(3):
vectors_y[i, :] = np.linalg.pinv(yRot.transpose()) @ vectors_x[i, :]
zrotation = np.arctan2(vectors_y[0, 0], vectors_y[0, 1])
zRot = np.array([[np.cos(zrotation), -np.sin(zrotation), 0],
[np.sin(zrotation), np.cos(zrotation), 0],
[0, 0, 1]])
vectors_z = np.zeros((3, 3))
for i in range(3):
vectors_z[i, :] = np.linalg.pinv(zRot.transpose()) @ vectors_y[i, :]
给出三个旋转正交向量:
>vectors_z
>array([[-1.11022302e-16, 1.00000000e+00, 3.19660393e-09],
[ 1.00000000e+00, -3.70417658e-09, -2.77555756e-16],
[ 2.12261116e-09, -1.98949113e-09, -1.00000000e+00]])
我需要在代码中更改什么才能使其处于正确的方向,如下所示:
array([[ 1, 0, 0],
[ 0, 1, 0],
[ 0, 0, 1]])
我知道可以通过以正确的顺序旋转向量90/180度来实现这一点,但必须有一种更有效的方法,通过在上面的代码中执行其他操作来实现这一点
谢谢你的时间
我明白了。切换到ZYZ旋转模式并重新定义欧拉角计算方法。希望有一天这能帮助别人
相关问题 更多 >
编程相关推荐