Python 从三维变换矩阵中提取旋转矩阵

Python 从三维变换矩阵中提取旋转矩阵,python,matrix,Python,Matrix,我用我在网上找到的一些关于矩阵的信息做了一段代码。但我一直坚持从SRT中提取旋转矩阵 def getRotationMatrix (m): scale = m.getScale() #return a Vector4 with the length of every row scaleMatrix = PMatrix4() #Initialize the scale matrix for x in xrange (4): scaleMatrix[x,x]

我用我在网上找到的一些关于矩阵的信息做了一段代码。但我一直坚持从SRT中提取旋转矩阵

def getRotationMatrix (m):
    scale = m.getScale() #return a Vector4 with the length of every row
    scaleMatrix = PMatrix4() #Initialize the scale matrix 
    for x in xrange (4):
        scaleMatrix[x,x] = scale[x] # set the scale factors on the diagonal
    rm = m*scaleMatrix.inverse() # and multiply the SRT matrice by the inverse
    return rm
似乎在大多数情况下都可以正常工作,但例如,对于此输入:

m = [-12.175876450247891, 5.807595155923971, 19.849933782589485, 0.0], [-13.991742515447003, -19.27618605313048, -2.9427525595147523, 0.0], [-15.230862551074761, 13.065239750956977, -13.165118161273075, 0.0], [0.0, 0.0, 0.0, 1.0]
这返回了一个错误的结果,第三行是负数。
我哪里做错了?

你在这里依赖的数学对我来说似乎是假的。但也许我误解了你的意图。嗨,我只是想提取一个没有旋转(和平移)的比例矩阵。(我反转了“旋转”和“缩放”)缩放矩阵是对角的,但由任意矩阵进行的缩放通常不是轴对齐的。您似乎在假设它是?什么是
getScale()
?您知道比例和转换量吗?