Esempio n. 1
0
 def __init__(self, radius, pos=(0, 0), vel=(0, 0), **kwds):
     radius = float(radius)
     super(Circle, self).__init__(
         pos, vel,
         base_shape=shapes.Circle(radius, null2D),
         cbb_radius=radius,
         **kwds
     )
Esempio n. 2
0
    def __init__(self,
                 pos=null2D, vel=null2D,
                 theta=0.0, omega=0.0,
                 adamping=None,
                 density=None, mass=None, inertia=None,
                 base_shape=shapes.Circle(1),
                 cbb_radius=1.0,
                 flags=DEFAULT_FLAGS, **kwargs):

        super().__init__(pos, vel, flags=flags, **kwargs)

        # State variables
        self._theta = float(theta)
        self._omega = float(omega)
        self._alpha = 0.0

        # Collision and shapes
        self.base_shape = base_shape
        self.cbb_radius = cbb_radius
        self._shape = None

        # Makes mass, inertial and density consistent
        if density is not None:
            density = float(density)
            if mass is None:
                mass = density * self.area()
            else:
                mass = float(mass)
            if inertia is None:
                inertia = density * \
                          self.area() * self.ROG_sqr() / INERTIA_SCALE
            else:
                inertia = float(inertia)
        elif mass is not None:
            mass = float(mass)
            try:
                density = mass / self.area()
            except ZeroDivisionError:
                density = float('inf')
            if inertia is None:
                inertia = mass * self.ROG_sqr() / INERTIA_SCALE
            else:
                inertia = float(inertia)
        else:
            density = 1.0
            area = self.area()
            if area:
                mass = density * self.area()
                if inertia is None:
                    inertia = density * \
                              self.area() * self.ROG_sqr() / INERTIA_SCALE
                else:
                    inertia = float(inertia)
            else:
                mass = 1.0
                density = float('inf')
                inertia = 0.0

        self._invmass = safe_div(1.0, mass)
        self._invinertia = safe_div(1.0, inertia)
        self._density = float(density)
Esempio n. 3
0
 def cbb(self):
     return shapes.Circle(self.cbb_radius, self.pos)