Package pymunk :: Class Body
[frames] | no frames]

Class Body

object --+
         |
        Body

A rigid body

Instance Methods
 
__init__(self, mass=None, moment=None)
Create a new Body
 
__del__(self)
 
apply_impulse(self, j, r=(0, 0))
Apply the impulse j to body at a relative offset (important!) r from the center of gravity. Both r and j are in world coordinates.
 
reset_forces(self)
Zero both the forces and torques accumulated on body
 
apply_force(self, f, r=(0, 0))
Apply (accumulate) the force f on body at a relative offset (important!) r from the center of gravity.
 
apply_damped_spring(self, b, anchor1, anchor2, rlen, k, dmp, dt)
Apply a spring force between this body and b at anchors anchr1 and anchr2 respectively.
 
activate(self)
Wake up a sleeping or idle body.
 
sleep(self)
Force a body to fall asleep immediately.
 
sleep_with_group(self, body)
Force a body to fall asleep immediately along with other bodies in a group.
 
local_to_world(self, v)
Convert body local coordinates to world space coordinates
 
world_to_local(self, v)
Convert world space coordinates to body local coordinates

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods
 
update_velocity(body, gravity, damping, dt)
Default rigid body velocity integration function.
 
update_position(body, dt)
Default rigid body position integration function.
Properties
  mass
  moment
  angle
The rotation of the body.
  rotation_vector
  torque
  position
  velocity
  velocity_limit
  angular_velocity
  angular_velocity_limit
  force
  velocity_func
The velocity callback function. The velocity callback function is called each time step, and can be used to set a body's velocity.
  position_func
The position callback function. The position callback function is called each time step and can be used to update the body's position.
  kinetic_energy
Get the kinetic energy of a body.
  is_sleeping
Returns true if the body is sleeping.
  is_rogue
Returns true if the body has not been added to a space.
  is_static
Returns true if the body is a static body

Inherited from object: __class__

Method Details

__init__(self, mass=None, moment=None)
(Constructor)

 

Create a new Body

To create a static body, pass in None for mass and moment.

Overrides: object.__init__

update_velocity(body, gravity, damping, dt)
Static Method

 

Default rigid body velocity integration function.

Updates the velocity of the body using Euler integration.

update_position(body, dt)
Static Method

 

Default rigid body position integration function.

Updates the position of the body using Euler integration. Unlike the velocity function, it's unlikely you'll want to override this function. If you do, make sure you understand it's source code (in Chipmunk) as it's an important part of the collision/joint correction process.

apply_impulse(self, j, r=(0, 0))

 
Apply the impulse j to body at a relative offset (important!) r from the center of gravity. Both r and j are in world coordinates.
Parameters:
  • j ((x,y) or Vec2d) - Impulse to be applied
  • r ((x,y) or Vec2d) - Offset the impulse with this vector

apply_force(self, f, r=(0, 0))

 

Apply (accumulate) the force f on body at a relative offset (important!) r from the center of gravity.

Both r and f are in world coordinates.

Parameters:
  • f ((x,y) or Vec2d) - Force in world coordinates
  • r ((x,y) or Vec2d) - Offset in world coordinates

apply_damped_spring(self, b, anchor1, anchor2, rlen, k, dmp, dt)

 

Apply a spring force between this body and b at anchors anchr1 and anchr2 respectively.

Note not solving the damping forces in the impulse solver causes problems with large damping values. There is a new constraint type DampedSpring that should be used instead.

Parameters:
  • b (Body) - The other body
  • anchor1 ((x,y) or Vec2d) - Anchor point on the first body
  • anchor2 ((x,y) or Vec2d) - Anchor point on the second body
  • k (float) - The spring constant (force/distance) (Young's modulus)
  • rlen (float) - The rest length of the spring
  • dmp (float) - The damping constant (force/velocity)
  • dt (float) - The time step to apply the force over.

local_to_world(self, v)

 
Convert body local coordinates to world space coordinates
Parameters:
  • v ((x,y) or Vec2d) - Vector in body local coordinates

world_to_local(self, v)

 
Convert world space coordinates to body local coordinates
Parameters:
  • v ((x,y) or Vec2d) - Vector in world space coordinates

Property Details

mass

Get Method:
_get_mass(self)
Set Method:
_set_mass(self, mass)

moment

Get Method:
_get_moment(self)
Set Method:
_set_moment(self, moment)

angle

The rotation of the body.

Note If you get small/no changes to the angle when for example a ball is "rolling" down a slope it might be because the Circle shape attached to the body or the slope shape does not have any friction set.

Get Method:
_get_angle(self)
Set Method:
_set_angle(self, angle)

rotation_vector

Get Method:
_get_rotation_vector(self)

torque

Get Method:
_get_torque(self)
Set Method:
_set_torque(self, t)

position

Get Method:
_get_position(self)
Set Method:
_set_position(self, pos)

velocity

Get Method:
_get_velocity(self)
Set Method:
_set_velocity(self, vel)

velocity_limit

Get Method:
_get_velocity_limit(self)
Set Method:
_set_velocity_limit(self, vel)

angular_velocity

Get Method:
_get_angular_velocity(self)
Set Method:
_set_angular_velocity(self, w)

angular_velocity_limit

Get Method:
_get_angular_velocity_limit(self)
Set Method:
_set_angular_velocity_limit(self, w)

force

Get Method:
_get_force(self)
Set Method:
_set_force(self, f)

velocity_func

The velocity callback function. The velocity callback function is called each time step, and can be used to set a body's velocity.

func(body, gravity, damping, dt) -> None

Callback Parameters
body : Body
Body that should have its velocity calculated
gravity : Vec2d
The gravity vector
damping : float
The damping
dt : float
Delta time since last step.
Set Method:
_set_velocity_func(self, func) - The velocity callback function. The velocity callback function is called each time step, and can be used to set a body's velocity.

position_func

The position callback function. The position callback function is called each time step and can be used to update the body's position.

func(body, dt) -> None

Callback Parameters
body : Body
Body that should have its velocity calculated
dt : float
Delta time since last step.
Set Method:
_set_position_func(self, func) - The position callback function. The position callback function is called each time step and can be used to update the body's position.

kinetic_energy

Get the kinetic energy of a body.
Get Method:
_get_kinetic_energy(self)

is_sleeping

Returns true if the body is sleeping.
Get Method:
_is_sleeping(self)

is_rogue

Returns true if the body has not been added to a space.
Get Method:
_is_rogue(self)

is_static

Returns true if the body is a static body
Get Method:
_is_static(self)