Exemplo n.º 1
0
Arquivo: props.py Projeto: trelau/AFEM
class ShapeProps(object):
    """
    Base class for shape properties.
    """

    def __init__(self):
        self._props = GProp_GProps()

    @property
    def mass(self):
        """
        :return: The mass of the shape. This corresponds to total length for
            linear properties, total area for surface properties, or total
            volume for volume properties.
        :rtype: float
        """
        return self._props.Mass()

    @property
    def cg(self):
        """
        :return: The center of gravity.
        :rtype: afem.geometry.entities.Point
        """
        gp_pnt = self._props.CentreOfMass()
        return Point(gp_pnt.X(), gp_pnt.Y(), gp_pnt.Z())

    @property
    def static_moments(self):
        """
        :return: The static moments of inertia Ix, Iy, and Iz.
        :rtype: tuple(float)
        """
        return self._props.StaticMoments(0., 0., 0.)

    @property
    def matrix_of_inertia(self):
        """
        :return: The 3 x 3 matrix of inertia.
        :rtype: numpy.ndarray
        """
        gp_mat = self._props.MatrixOfInertia()
        matrix = []
        for j in range(1, 4):
            row = []
            for i in range(1, 4):
                row.append(gp_mat.Value(i, j))
            matrix.append(row)
        return array(matrix, dtype=float)

    def moment_of_inertia(self, axis):
        """
        Compute the moment of inertia about the axis.

        :param afem.geometry.entities.Axis1 axis: The axis.

        :return: The moment of inertia.
        :rtype: float
        """
        return self._props.MomentOfInertia(axis)
Exemplo n.º 2
0
def cube_inertia_properties():
    """ Compute the inertia properties of a shape
    """
    # Create and display cube
    print("Creating a cubic box shape (50*50*50)")
    cube_shape = BRepPrimAPI_MakeBox(50., 50., 50.).Shape()
    # Compute inertia properties
    props = GProp_GProps()
    brepgprop_VolumeProperties(cube_shape, props)
    # Get inertia properties
    mass = props.Mass()
    cog = props.CentreOfMass()
    matrix_of_inertia = props.MatrixOfInertia()
    # Display inertia properties
    print("Cube mass = %s" % mass)
    cog_x, cog_y, cog_z = cog.Coord()
    print("Center of mass: x = %f;y = %f;z = %f;" % (cog_x, cog_y, cog_z))
    print("Matrix of inertia", matrix_of_inertia)