コード例 #1
0
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)
コード例 #2
0
def on_select(shapes):
    """

    Parameters
    ----------
    shape : TopoDS_Shape

    """
    g1 = GProp_GProps()

    for shape in shapes:
        brepgprop_LinearProperties(shape, g1)
        mass = g1.Mass()
        centre_of_mass = g1.CentreOfMass()
        com_x = centre_of_mass.X()
        com_y = centre_of_mass.Y()
        com_z = centre_of_mass.Z()
        static_moments = g1.StaticMoments()
        print("shape {shape}: \n mass: {mass}"
              "\n center of mass: {com_x}, {com_y}, {com_z}"
              "\n static moments: {static_moments}".format(**vars()))