how to edit object rotation of an object in ifcopenshell

Hi,
I was looking to change the rotation of an object in ifcopenshell.
I have seen post in which the placement.get_local_placement(ifcelement.ObjectPlacement) is decomposed to location, rotation and scale with mathutils
Now, what kind of matrix transformation do I do for the rotation of the object. Is it done through ifcopenshell.api.geometry.edit_object_placement?
Any pointers or code references would help. Thanks

Tagged:

Comments

  • edit_object_placement is the correct API function to use. It expects a 4x4 matrix. This is a standard 4x4 matrix used throughout computer graphics: https://en.wikipedia.org/wiki/Transformation_matrix

    You can see the 4x4 matrix also documented here: https://blenderbim.org/docs-python/ifcopenshell-python/geometry_processing.html

    theoryshaw
  • Thanks Moult

  • ArvArv
    edited April 2023

    Hi @Moult,
    I have tried a test on object rotation and its working perfectly. below is my code and the screenshot from BB.
    I was wondering if this is the correct way of doing the rotation. I have made a 3x3 matrix and then converted into a 4x4 by adding additional col and row and I dont think this is the right approach :(. Is this 4x4 matrix a quaternion?
    Also, I observed that I was loosing the existing translation or rotation and that I have to mention all the existing translations and rotations again. How do I only apply the new rotation to the object with existing rotation/translation?

    beam_plc = placement.get_local_placement(beam.ObjectPlacement)
    
    beam_matrix = mathutils.Matrix(beam_plc)
    
    phi, psi = -np.pi/2, np.pi/2
    
    rotX = mathutils.Matrix([[1,0,0],
                             [0, np.cos(phi), -np.sin(phi)], 
                             [0, np.sin(phi), np.cos(phi)]])
    
    rotZ = mathutils.Matrix([[np.cos(psi), -np.sin(psi), 0], 
                            [np.sin(psi), np.cos(psi), 0],
                            [0,0,1]])
    rotation = rotX@rotZ
    
    translation = np.array([0, -0.08, 2.04])
    last_row = np.array([0.,0.,0.,1.])
    
    rotation_mat = np.vstack((np.hstack((np.matrix(rotation), translation.reshape(-1,1))), last_row))
    
    new_matrix = mathutils.Matrix(rotation_mat.tolist())
    
    run('geometry.edit_object_placement', f, product=beam, matrix = new_matrix)
    

    before
    after

Sign In or Register to comment.