# pagoda.physics.Body¶

class pagoda.physics.Body(name, world, density=1000.0, mass=None, **shape)[source]

This class wraps things that participate in the ODE physics simulation.

This class basically provides lots of Python-specific properties that call the equivalent ODE getters and setters for things like position, rotation, etc.

__init__(name, world, density=1000.0, mass=None, **shape)[source]

Methods

 __init__(name, world[, density, mass]) add_force(force[, relative, position, ...]) Add a force to this body. add_torque(torque[, relative]) Add a torque to this body. body_to_world(position) Convert a body-relative offset to world coordinates. connect_to(joint, other_body[, offset, ...]) Move another body next to this one and join them together. join_to(joint[, other_body]) Connect this body to another one using a joint. relative_offset_to_world(offset) Convert a relative body offset to world coordinates. rotate_to_body(x) Rotate the given vector to the same orientation as this body. world_to_body(position) Convert a point in world coordinates to a body-relative offset.

Attributes

 angular_velocity Current angular velocity of this body (in world coordinates). follows_gravity True iff this body follows gravity. force Current net force acting on this body (in world coordinates). is_kinematic True iff this body is kinematic. linear_velocity Current linear velocity of this body (in world coordinates). mass The ODE mass object for this body. position The (x, y, z) coordinates of the center of this body. quaternion The (w, x, y, z) rotation quaternion for this body. rotation The rotation matrix for this body. state The state of this body includes: torque Current net torque acting on this body (in world coordinates).
add_force(force, relative=False, position=None, relative_position=None)[source]

Add a force to this body.

Parameters: force : 3-tuple of float A vector giving the forces along each world or body coordinate axis. relative : bool, optional If False, the force values are assumed to be given in the world coordinate frame. If True, they are assumed to be given in the body-relative coordinate frame. Defaults to False. position : 3-tuple of float, optional If given, apply the force at this location in world coordinates. Defaults to the current position of the body. relative_position : 3-tuple of float, optional If given, apply the force at this relative location on the body. If given, this method ignores the position parameter.
add_torque(torque, relative=False)[source]

Add a torque to this body.

Parameters: force : 3-tuple of float A vector giving the torque along each world or body coordinate axis. relative : bool, optional If False, the torque values are assumed to be given in the world coordinate frame. If True, they are assumed to be given in the body-relative coordinate frame. Defaults to False.
angular_velocity

Current angular velocity of this body (in world coordinates).

body_to_world(position)[source]

Convert a body-relative offset to world coordinates.

Parameters: position : 3-tuple of float A tuple giving body-relative offsets. position : 3-tuple of float A tuple giving the world coordinates of the given offset.
connect_to(joint, other_body, offset=(0, 0, 0), other_offset=(0, 0, 0), **kwargs)[source]

Move another body next to this one and join them together.

This method will move the other_body so that the anchor points for the joint coincide. It then creates a joint to fasten the two bodies together. See World.move_next_to() and World.join().

Parameters: joint : str The type of joint to use when connecting these bodies. other_body : Body or str The other body to join with this one. offset : 3-tuple of float, optional The body-relative offset where the anchor for the joint should be placed. Defaults to (0, 0, 0). See World.move_next_to() for a description of how offsets are specified. other_offset : 3-tuple of float, optional The offset on the second body where the joint anchor should be placed. Defaults to (0, 0, 0). Like offset, this is given as an offset relative to the size and shape of other_body.
follows_gravity

True iff this body follows gravity.

force

Current net force acting on this body (in world coordinates).

is_kinematic

True iff this body is kinematic.

join_to(joint, other_body=None, **kwargs)[source]

Connect this body to another one using a joint.

This method creates a joint to fasten this body to the other one. See World.join().

Parameters: joint : str The type of joint to use when connecting these bodies. other_body : Body or str, optional The other body to join with this one. If not given, connects this body to the world.
linear_velocity

Current linear velocity of this body (in world coordinates).

mass

The ODE mass object for this body.

position

The (x, y, z) coordinates of the center of this body.

quaternion

The (w, x, y, z) rotation quaternion for this body.

relative_offset_to_world(offset)[source]

Convert a relative body offset to world coordinates.

Parameters: offset : 3-tuple of float The offset of the desired point, given as a relative fraction of the size of this body. For example, offset (0, 0, 0) is the center of the body, while (0.5, -0.2, 0.1) describes a point halfway from the center towards the maximum x-extent of the body, 20% of the way from the center towards the minimum y-extent, and 10% of the way from the center towards the maximum z-extent. position : 3-tuple of float A position in world coordinates of the given body offset.
rotate_to_body(x)[source]

Rotate the given vector to the same orientation as this body.

Parameters: x : 3-tuple of float A point in three dimensions. xrot : 3-tuple of float The same point after rotation into the orientation of this body.
rotation

The rotation matrix for this body.

state

The state of this body includes:

• name of the body (str)
• position (3-tuple)
• quaternion (4-tuple)
• linear velocity (3-tuple)
• angular velocity (3-tuple)
torque

Current net torque acting on this body (in world coordinates).

world_to_body(position)[source]

Convert a point in world coordinates to a body-relative offset.

Parameters: position : 3-tuple of float A world coordinates position. offset : 3-tuple of float A tuple giving the body-relative offset of the given position.