Extract rotation / scale / position from IFC openshell transformation matrix python
Hi all !
I'm a beginner to IFC files and transformation matrices and wondered I could extract rotation / scale and position from a transformation matrix using python.
I'm using ifcopenshell and shape.transformation.matrix.data gives me this :
(-1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0, 8.382999999999972, -17.5915, 0.0)
So, now from this tuple I know that the matrix is supposedly mapped like this :
matrix([[ -1. , 0. , 0. , 8.383 ],
[ 0. , -1. , 0. , -17.5915],
[ 0. , 0. , 1. , 0. ],
[ 0. , 0. , 0. , 1. ]])
But I don't know how to obtain this matrix and how to extract the data I want from it. I'm supposed to get :
rotation (x,y,z) : 0, 0, 180
scale : 1, 1, 1
location ; 8.3, -17.5, 0
So any idea on how to do it using ifcopenshell and python ?
Thanks!
Comments
There is probably a numpy function that will do this for you, but a transformation matrix for a location (coor) and 2D rotation (theta) looks like this:
Thanks for your answer ! But in my case it's for a 3D environment
If you need Euler angles, you can use the left upper 3x3 matrix as rotation matrix. I don't think numpy has a method for this but scipy.spatial.transform.Rotation.as_euler is the method from SciPy you could use.
Translation/position is as @brunopostle said the right side of the matrix.
For scale (don't pin me on this) you can extract each component (X, Y, Z) by computing the magnitude of respectively the first, second and third column of the matrix.
After some research and many help from Dion Moult on ifcopenshell's github, I used mathutils matrix in order to get all the data I needed, thanks for the help !
Linking to the bugreport for those interested: https://github.com/IfcOpenShell/IfcOpenShell/issues/1440