【发布时间】:2018-12-17 03:07:19
【问题描述】:
我有一个任务来检查一个矩阵是否是一个旋转矩阵,我编写代码如下:
import numpy as np
def isRotationMatrix(R):
# some code here
# return True or False
R = np.array([
[0, 0, 1],
[1, 0, 0],
[0, 1, 0],
])
print(isRotationMatrix(R)) # Should be True
R = np.array([
[-1, 0, 0],
[0, 1, 0],
[0, 0, 1],
])
print(isRotationMatrix(R)) # Should be False
我不知道如何实现函数isRotationMatrix。
我的幼稚实现,它只适用于 3x3 矩阵:
def isRotationMatrix(R_3x3):
should_be_norm_one = np.allclose(np.linalg.norm(R_3x3, axis=0), np.ones(shape=3))
x = R_3x3[:, 0].ravel()
y = R_3x3[:, 1].ravel()
z = R_3x3[:, 2].ravel()
should_be_perpendicular = \
np.allclose(np.cross(x, y), z) \
and np.allclose(np.cross(y, z), x) \
and np.allclose(np.cross(z, x), y)
return should_be_perpendicular and should_be_norm_one
【问题讨论】:
-
不是投反对票的人,但是虽然您的问题标题很明确,但您的“我看了,什么也没找到,请,谢谢”的内容不构成问题。
标签: python numpy rotational-matrices