Invert Matrix

   2147   2   1
User Avatar
Member
326 posts
Joined: Jan. 2013
Offline
Hello!

There is the following code and a very strange result which returns the function of inverts. How does the invert function actually work for zero determinant matrices?

matrix3 matA = { {1,2,3}, {4,5,6}, {7,8,9} };

// Find the determinant of the matrix
// If the determinant value is zero, then an inverted matrix cannot be found for such a matrix.

int det = determinant(matA); // det == 0

matrix3 matB = invert(matA); // { {-0.75, 0.5, 0.25}, {-0.5, 0, -0.5}, {0.5833, 0.5, -0.083} }
User Avatar
Member
326 posts
Joined: Jan. 2013
Offline
Maybe in the vex there is some kind of internal error of the data? Because the python strictly refers to this condition.

>>> hou.Matrix3([[1,2,3],[4,5,6],[7,8,9]]).inverted()

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/opt/hfs17.0.497/houdini/python2.7libs/hou.py", line 39294, in inverted
    return _hou.Matrix3_inverted(*args)
OperationFailed: The attempted operation failed.
User Avatar
Member
12 posts
Joined: May 2017
Offline
Hi, I think you're right, VEX isn't handling this case correctly.
The docs say [www.sidefx.com] that if the input matrix is singular (determinant = 0) it should return the original matrix but that clearly isn't happening… Looks like a bug report to me

In the meantime, I guess you could explicitly check the determinant yourself.
  • Quick Links