Python 从齐次矩阵确定变换矩阵

Python 从齐次矩阵确定变换矩阵,python,numpy,matrix,Python,Numpy,Matrix,我想找到平移矩阵、旋转矩阵以及比例矩阵。下面是我的代码 import numpy as np def get_rotation_from_homogeneous_transform(transform): s = transform.shape if s[0] != s[1]: raise ValueError('Matrix must be a 4x4 homogenous transformation', s) n = s[0] r

我想找到平移矩阵、旋转矩阵以及比例矩阵。下面是我的代码

import numpy as np

def get_rotation_from_homogeneous_transform(transform):
    
    s = transform.shape
    if s[0] != s[1]:
        raise ValueError('Matrix must be a 4x4 homogenous transformation', s)
    n = s[0]
    rotation = transform[0:n - 1, 0:n - 1]
    return rotation

homogeneous_matrix = np.array([[-0.008189, 0.000428, -0.999900, 0.000000],
[0.758580, 0.651582, 0.008000, 0.000000],
 [0.651582, 0.758580, -0.011300, 0.000000],
  [1.294619, 0.885227, 1.358000, 1.000000]]).astype(np.float32).T

rotM = get_rotation_from_homogeneous_transform(homogeneous_matrix)

我是否正确提取了旋转矩阵?如何提取平移和缩放矩阵?

这是否回答了您的问题?另见@RichieV No。。它们都不是关于从同质矩阵中提取腐烂矩阵