- Sim
- Graph
- Zeit Graph
- MehrGraphen

This simulation uses the Rigid Body Physics Engine to show objects moving in 2 dimensions with various forces applied.

Click near an object to exert a spring force with your mouse. With the keyboard you can control four "thrusters". The keys S,D,F,E control thrust on block1. The keys J,K,L,I (and also the arrow keys) control thrust on block2. You can also set gravity and damping (friction). You can choose from one to six objects. The mass of the green object is adjustable (the others are set to mass 1.0).

Also available are: open source code, documentation and a simple-compiled version which is more customizable.

If you play around with the simulation shown above, you will notice that it can easily get "stuck", which means that objects wind up overlapping. The section below about Resting Contact explains why this happens.

Here is a picture of how the keyboard controls are arranged. If the keys don't work, try clicking near an object first - this ensures that keystrokes are passed to the simulation.

keyboard thruster controls

Click the "show energy" checkbox to see the bar graph showing the potential, rotational and translational energy.

energy bar graph

See the section on Energy and Momentum for how these quantities are calculated.

rigid body variables

Ignoring collisions for the moment, we develop the equations of motion for the objects. The forces on the objects are

- Gravity
- Friction
- Thrust (keyboard controls)
- Spring (mouse control)

For each body, there are three variables to specify position:

*x*= horizontal position of center of mass*y*= vertical position of center of mass*θ*= angle of rotation

In addition, each body has a velocity corresponding to each of these positions:

*x'*=*v*= horizontal velocity of center of mass_{x}*y'*=*v*= vertical velocity of center of mass_{y}*θ'*=*ω*= angular velocity

The equations of motion for the body involve the total force
F = (*F _{x}*,

*F _{x}* =

where
*m* =
mass and
*I* =
moment of inertia about the center of mass
(moment of inertia is defined in the next section). Note that we indicate vectors, such
as
F
, with bold and an overline.

thrust force vector

We now build up the equations of motion by adding in one force at a time, beginning
with the thrust force. Let
T = (*T _{x}*,

*m* *x''* = *T _{x}*

In these equations it doesn't matter where on the body the thrust force is applied. The point P can be anywhere on the body, yet because the body is rigid the thrust accelerates the entire body. On the other hand, for rotational movement it matters a great deal where on the body the thrust is applied.

*Moment of inertia* is the equivalent of mass for rotational physics. It
measures how difficult it is to rotate a body about a given point. Since our rectangle
bodies rotate freely about their center of mass, we use center of mass as the point for
calculating moment of inertia. From a physics textbook you can find the equation for
the moment of inertia about the center of a thin rectangular plate. It is given by

*I* = *m* (width^{2} + height^{2}) ⁄ 12

Let
R = (*R _{x}*,

R × T = *R _{x}*

so we have

*I* *θ''* = R × T

Actually torque is a vector, but since we are working in 2 dimensions we know that torque is always perpendicular to the plane and so we aren't using vector notation for it. The true vector cross product results in a vector. So the above cross product corresponds to the following 3 dimensional calculation:

(*R _{x}*,

You can see that the result is always perpendicular to the plane, with zero
*x*
and
*y*
components. The general vector cross product of two vectors
is defined as:

(*x*, *y*, *z*) × (*u*, *v*, *w*)
= (*y* *w* − *z* *v*, −*x* *w* + *z* *u*, *x* *v* − *y* *u*)

The spring force in the simulation operates along the vector from point
P
on the body to the mouse position, call this vector
L
. The
spring force is
B = (*B _{x}*,

*m* *x''* = *T _{x}* +

Let
*g* =
the gravitational constant. Gravity causes a force on the center of
mass of
−*m* *g*
in the vertical direction leading to

*m* *y''* = *T _{y}* +

Because gravity works on all points of the body, no torque is generated by gravity.

Damping (friction) causes a force opposite to the direction of motion. The faster you
go, the more friction resists your motion. So the magnitude of the damping force is
proportional to the velocity. Let
*k* =
the proportional damping constant.
Adding this to our equations of motion gives

m x'' = T + _{x}B − _{x}k x'
| (1) |

m y'' = T + _{y}B − _{y}m g − k y'
| (2) |

I θ'' = R×T + R×B − k θ'
| (3) |

In a more realistic simulation, there may be different damping constants for rotational versus translational motion. But here, we use the same constant for both.

Equations (1-3) are the equations of motion for one of our rectangular bodies. As long as no collision occurs, these equations are in charge. Here is a recap of some of the variables:

*m*= mass*g*= gravity constant*k*= damping (friction) constant- T = thrust force vector
- B = spring force vector
- R = vector from center to point P where thrust is applied

The above section shows the equations of motion for bodies affected by gravity, damping, a thrust force and a spring force. To use the Runge Kutta method for solving a set of differential equations we need to convert the above three second order equations into six first order equations. Define the velocity variables

*v*=_{x}*x'*= horizontal velocity*v*=_{y}*y'*= vertical velocity*ω*=*θ'*= angular velocity

Then equations (1-3) become 6 first order differential equations

*x'* = *v _{x}*

These equations are now in the form needed for solving numerically with the
Runge-Kutta method. Each rectangle body will have its own set of 6 variables (3
positions
*x*, *y*, *θ*
and 3 velocities
*v _{x}*,

This section explains how the energy and momentum of the objects are calculated. See the description of the energy bar graph for how to observe these quantities in the simulation.

If there is no loss of energy to friction (damping = 0 ) or during collisions (elasticity = 1 ) then the energy of the system should not change.

A collision between objects should not change the angular momentum. However, a collision with a wall will not preserve angular momentum because the super massive walls are not included in the calculations of the momentum of the objects.

Gravitational energy is given by
*m* *g* *h*
where
*h* =
height of the
object's center of mass above the floor.

Translational energy is
^{1}⁄_{2} *m* v^{2}
where
v
is the
velocity vector for the object's center of mass. Note that we use vector dot product to
square the velocity vector.

Rotational energy is
1/2 *I* *ω*^{2}
where
*I*
is the moment of inertia
and
*ω*
is the angular velocity.

Linear momentum in the horizontal direction is given by
*m* *v _{x}*
, in the
vertical direction by

Angular momentum is measured with regard to a particular point in space, for example the origin. It is given by:

*I* *ω* k + *m* r × v

where
r
is the distance vector from the origin to the object's center of
mass. The vector
k
is the unit
*z*
vector, which points out of the
*x*-*y*
plane. You can see that the angular momentum has two components: the
spinning component
*I* *ω* k
and the rotation about the origin given by the
vector cross-product
*m* r × v
.

This web page was first published February 2003.