pymunk.constraint Module

A constraint is something that describes how two bodies interact with each other. (how they constrain each other). Constraints can be simple joints that allow bodies to pivot around each other like the bones in your body, or they can be more abstract like the gear joint or motors.

This submodule contain all the constraints that are supported by pymunk.

Chipmunk has a good overview of the different constraint on youtube which works fine to showcase them in pymunk as well. http://www.youtube.com/watch?v=ZgJJZTS0aMM

class pymunk.constraint.Constraint(constraint=None)[source]

Bases: object

Base class of all constraints.

You usually don’t want to create instances of this class directly, but instead use one of the specific constraints such as the PinJoint.

a

The first of the two bodies constrained

activate_bodies()[source]
b

The second of the two bodies constrained

error_bias

The rate at which joint error is corrected.

Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

impulse

Get the last impulse applied by this constraint.

max_bias

The maximum rate at which joint error is corrected. Defaults to infinity

max_force

The maximum force that the constraint can use to act on the two bodies. Defaults to infinity

class pymunk.constraint.DampedRotarySpring(a, b, rest_angle, stiffness, damping)[source]

Bases: pymunk.constraint.Constraint

Like a damped spring, but works in an angular fashion

a

The first of the two bodies constrained

activate_bodies()
b

The second of the two bodies constrained

damping

How soft to make the damping of the spring.

error_bias

The rate at which joint error is corrected.

Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

impulse

Get the last impulse applied by this constraint.

max_bias

The maximum rate at which joint error is corrected. Defaults to infinity

max_force

The maximum force that the constraint can use to act on the two bodies. Defaults to infinity

rest_angle

The relative angle in radians that the bodies want to have

stiffness

The spring constant (Young’s modulus).

torque_func

Set the torque function

func(self, relative_angle) -> torque

Callback Parameters
relative_angle : float
The relative angle
class pymunk.constraint.DampedSpring(a, b, anchr1, anchr2, rest_length, stiffness, damping)[source]

Bases: pymunk.constraint.Constraint

A damped spring

a

The first of the two bodies constrained

activate_bodies()
anchr1
anchr2
b

The second of the two bodies constrained

damping

How soft to make the damping of the spring.

error_bias

The rate at which joint error is corrected.

Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

impulse

Get the last impulse applied by this constraint.

max_bias

The maximum rate at which joint error is corrected. Defaults to infinity

max_force

The maximum force that the constraint can use to act on the two bodies. Defaults to infinity

rest_length

The distance the spring wants to be.

stiffness

The spring constant (Young’s modulus).

class pymunk.constraint.GearJoint(a, b, phase, ratio)[source]

Bases: pymunk.constraint.Constraint

Keeps the angular velocity ratio of a pair of bodies constant.

a

The first of the two bodies constrained

activate_bodies()
b

The second of the two bodies constrained

error_bias

The rate at which joint error is corrected.

Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

impulse

Get the last impulse applied by this constraint.

max_bias

The maximum rate at which joint error is corrected. Defaults to infinity

max_force

The maximum force that the constraint can use to act on the two bodies. Defaults to infinity

phase
ratio
class pymunk.constraint.GrooveJoint(a, b, groove_a, groove_b, anchr2)[source]

Bases: pymunk.constraint.Constraint

Similar to a pivot joint, but one of the anchors is on a linear slide instead of being fixed.

a

The first of the two bodies constrained

activate_bodies()
anchr2
b

The second of the two bodies constrained

error_bias

The rate at which joint error is corrected.

Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

groove_a
groove_b
impulse

Get the last impulse applied by this constraint.

max_bias

The maximum rate at which joint error is corrected. Defaults to infinity

max_force

The maximum force that the constraint can use to act on the two bodies. Defaults to infinity

class pymunk.constraint.PinJoint(a, b, anchr1=(0, 0), anchr2=(0, 0))[source]

Bases: pymunk.constraint.Constraint

Keeps the anchor points at a set distance from one another.

a

The first of the two bodies constrained

activate_bodies()
anchr1
anchr2
b

The second of the two bodies constrained

distance
error_bias

The rate at which joint error is corrected.

Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

impulse

Get the last impulse applied by this constraint.

max_bias

The maximum rate at which joint error is corrected. Defaults to infinity

max_force

The maximum force that the constraint can use to act on the two bodies. Defaults to infinity

class pymunk.constraint.PivotJoint(a, b, *args)[source]

Bases: pymunk.constraint.Constraint

Simply allow two objects to pivot about a single point.

a

The first of the two bodies constrained

activate_bodies()
anchr1
anchr2
b

The second of the two bodies constrained

error_bias

The rate at which joint error is corrected.

Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

impulse

Get the last impulse applied by this constraint.

max_bias

The maximum rate at which joint error is corrected. Defaults to infinity

max_force

The maximum force that the constraint can use to act on the two bodies. Defaults to infinity

class pymunk.constraint.RatchetJoint(a, b, phase, ratchet)[source]

Bases: pymunk.constraint.Constraint

Works like a socket wrench.

a

The first of the two bodies constrained

activate_bodies()
angle
b

The second of the two bodies constrained

error_bias

The rate at which joint error is corrected.

Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

impulse

Get the last impulse applied by this constraint.

max_bias

The maximum rate at which joint error is corrected. Defaults to infinity

max_force

The maximum force that the constraint can use to act on the two bodies. Defaults to infinity

phase
ratchet
class pymunk.constraint.RotaryLimitJoint(a, b, min, max)[source]

Bases: pymunk.constraint.Constraint

Constrains the relative rotations of two bodies.

a

The first of the two bodies constrained

activate_bodies()
b

The second of the two bodies constrained

error_bias

The rate at which joint error is corrected.

Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

impulse

Get the last impulse applied by this constraint.

max
max_bias

The maximum rate at which joint error is corrected. Defaults to infinity

max_force

The maximum force that the constraint can use to act on the two bodies. Defaults to infinity

min
class pymunk.constraint.SimpleMotor(a, b, rate)[source]

Bases: pymunk.constraint.Constraint

Keeps the relative angular velocity of a pair of bodies constant.

a

The first of the two bodies constrained

activate_bodies()
b

The second of the two bodies constrained

error_bias

The rate at which joint error is corrected.

Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

impulse

Get the last impulse applied by this constraint.

max_bias

The maximum rate at which joint error is corrected. Defaults to infinity

max_force

The maximum force that the constraint can use to act on the two bodies. Defaults to infinity

rate

The desired relative angular velocity

class pymunk.constraint.SlideJoint(a, b, anchr1, anchr2, min, max)[source]

Bases: pymunk.constraint.Constraint

Like pin joints, but have a minimum and maximum distance. A chain could be modeled using this joint. It keeps the anchor points from getting to far apart, but will allow them to get closer together.

a

The first of the two bodies constrained

activate_bodies()
anchr1
anchr2
b

The second of the two bodies constrained

error_bias

The rate at which joint error is corrected.

Defaults to pow(1.0 - 0.1, 60.0) meaning that it will correct 10% of the error every 1/60th of a second.

impulse

Get the last impulse applied by this constraint.

max
max_bias

The maximum rate at which joint error is corrected. Defaults to infinity

max_force

The maximum force that the constraint can use to act on the two bodies. Defaults to infinity

min