Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help understanding shape matrix values #1440

Closed
baldash opened this issue Apr 21, 2021 · 4 comments
Closed

Help understanding shape matrix values #1440

baldash opened this issue Apr 21, 2021 · 4 comments

Comments

@baldash
Copy link

baldash commented Apr 21, 2021

Hi all,

I'm actually trying to read an IFC file with ifcopenshell in order to extract rotation, scale, and location of all walls. My problem here is that I'm absolutely not understanding the matrix values returned by the shapes objects. For example, for a wall with :
rotation (x,y,z) : 0, 0, 180
scale : 1, 1, 1
location ; 8.3, -17.5, 0

When I print shape.transformation.matrix.data I get :
(-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, the 3 last digits are the location, I'm assuming that the 3 previous from that are maybe the scale, because for all my walls it's the same value (I don't really understand why it's 0, 0, 1 for a 1, 1, 1 scale though), and after some research the 6 first digits seems to be related to rotation and orientation but I don't understand in which way.

Example of a second wall :
rotation (x,y,z) : 0, 0, -90
scale : 1, 1, 1
location ; 8.5, -0.4, 0

-> (0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 8.5915, -0.4170000000000275, 0.0)

And one last thing, I'm using BlenderBIM to visualilze the file and I'm using the element's tag to find the walls but I can't seem to find all of them using this technique so I don't know if I4m doing it right.

My code :

ifc = ifcopenshell.open(filename)

settings = ifcopenshell.geom.settings()
# settings.set(settings.USE_WORLD_COORDS, True)
iterator = ifcopenshell.geom.iterator(settings, ifc, multiprocessing.cpu_count())
valid_file = iterator.initialize()
if valid_file:
    while True:
        shape = iterator.get()
        element = ifc.by_guid(shape.guid)
        if (element.is_a("IfcWall")):
            print(str(shape.transformation.matrix.data) + ", tag -> " + element.Tag)
        if not iterator.next():
            break
@Moult
Copy link
Contributor

Moult commented Apr 21, 2021

The transformation matrix is a standard transformation matrix, simply that it is shown as a list instead of a matrix that you might be more familiar with. You can see the mapping here: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.6.0/src/blenderbim/blenderbim/bim/import_ifc.py#L807

When you follow that mapping...

(-1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0, 8.382999999999972, -17.5915, 0.0)

... maps to this:

matrix([[ -1.    ,   0.    ,   0.    ,   8.383 ],
        [  0.    ,  -1.    ,   0.    , -17.5915],
        [  0.    ,   0.    ,   1.    ,   0.    ],
        [  0.    ,   0.    ,   0.    ,   1.    ]])

If you want to convert to its components, such as the Euler rotation angles you seem to be after, you can use Blender's mathutils Matrix to do this easily since you are already experimenting in Blender.

>>> bm = Matrix(mat.tolist()) # mat is a numpy matrix
>>> bm.to_translation()
Vector((8.383000373840332, -17.59149932861328, 0.0))
>>> bm.to_scale()
Vector((1.0, 1.0, 1.0))
>>> bm.to_euler()
Euler((0.0, -0.0, 3.1415927410125732), 'XYZ')

Your code for tags looks fine, assuming Tag is unique, which it doesn't have to be. Perhaps you can elaborate more about what you're doing.

By the way, this is not really a bug, so you may be better suited to post this over a https://community.osarch.org/ - that way others can help chip in :)

@Moult Moult closed this as completed Apr 21, 2021
@baldash
Copy link
Author

baldash commented Apr 21, 2021

Thanks a lot for the help, it's way clearer now !

@baldash
Copy link
Author

baldash commented Apr 21, 2021

Is there any python library to do the transformation matrix data extractions (scale, rotation, position) ? Actually I'm using Blender only to visualize a BIM file, but I'm working outside of it with only python

@Moult
Copy link
Contributor

Moult commented Apr 21, 2021

This might help: https://www.meccanismocomplesso.org/en/3d-rotations-and-euler-angles-in-python/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants