pythonocc-core icon indicating copy to clipboard operation
pythonocc-core copied to clipboard

Get Location and Eulerian Angles in global coordinates of TopoDS_Shape that is a rotated and translated Box.

Open LuisGMM opened this issue 3 years ago • 0 comments

Hi everyone, I am trying to extract some data (mass, volume, area, position (of the center of mass) and its orientation, that is the angle that the figure is rotated about each global axis) from the attached STEP file, containing a 20 mm cube translated 40mm in every axis and rotated 30 deg in every axis.

I am able to get the rotation angles in the local coordinate system, which evidently are all 0. The process I use is:

from OCC.Core.BRepGProp import brepgprop
from OCC.Core.gp import gp_EulerSequence
from OCC.Core.GProp import GProp_GProps
from OCC.Core.TopoDS import TopoDS_Shape

from OCC.Extend.DataExchange import read_step_file


def main():

    path: str = ...
    shape: TopoDS_Shape = read_step_file(path)

    lprops = GProp_GProps()
    brepgprop.VolumeProperties(shape, lprops)

    mass_or_volume = lprops.Mass()

    lprops = GProp_GProps()
    brepgprop.SurfaceProperties(shape, lprops)

    area = lprops.Mass()

    center_of_mass = lprops.CentreOfMass().Coord()

    # For the location
    location = shape.Location()
    transformation = location.Transformation()
    point = transformation.TranslationPart()

    location_coords = point.X(), point.Y(), point.Z()

    # For the orientation
    location = shape.Location()
    transformation = location.Transformation()
    quaternion = transformation.GetRotation()

    rotation_angles = quaternion.GetEulerAngles(gp_EulerSequence.gp_Extrinsic_XYZ)

    print('Volume: ', mass_or_volume)
    print('Area: ', area)
    print('Center of mass: ', center_of_mass)
    print('Location coordinates: ', location_coords)
    print('Rotation angles: ', rotation_angles)


if __name__ == '__main__':
    main()

I suspect this happens because TopoDS_Shape.Location() returns the TopLoc_Location in the local coordinate system, but I am not sure.

Does anybody know how to extract these properties from a global (absolute) coordinate system ?

Thank you very much before hand.

LuisGMM avatar Jul 13 '22 13:07 LuisGMM