Вы находитесь на странице: 1из 10

Rigid Body Dynamics

CE1051A Advanced Game Technologies


University of Abertay Dundee
Zoe Sams
1001675
January 2014
Abstract
This paper will discuss the main principles behind Rigid Body Motion, relating to background
reading and an application created to practically demonstrate the fundamentals learnt through
the course of the Rigid Bodies section of Advanced Game Technologies. The paper will discuss,
the application created, results of various tests, and the underlying mathematics behind rigid
body calculations.
1 Introduction
Rigid bodies are systems of absolutely xed particles which share the same angular velocity. Cen-
trifugal forces do not apply to rigid bodies as the particles within the system do not move with
respect to each other (Lengyel, E. 2012).
Rigid bodies are often chosen for implementation in video games due to their simplicity, as they
are an idealisation of a solid body. All real world objects are technically soft bodies, but to rep-
resent this in a graphical application is computationally expensive. The chosen scenario for this
application is a cube placed with its centre of mass at the origin of world space. The cube is
interactable through some sort of user input, and the key variables are displayed with some sort of
visual representation. The expected reaction would be that the cube would translate and rotate in
dierent directions depending on where the user clicks to add a force. This application was created
in Unity using C#, and the cube will have an unconstrained rigid body component.
2 Rigid Body Motion
Rigid body motion should be thought of in two states, the motion of the centre of mass away
from the origin, and the rotation of the body around an axis passing through the centre of mass.
Four state variables make up a rigid body - position, orientation, linear momentum and angular
momentum. From these we can derive the linear and angular velocity. The constant qualities of a
rigid body include mass, and the inertia tensor in body space. (Bara, D. 2001)
1
In this report, the state of the rigid body at any time will be dened as
X(t) =
_
_
_
_
x(t)
Q(t)
P(t)
L(t)
_
_
_
_
2.1 Centre of Mass
If a body is absent of external forces, it rotates around its own centre of mass. The centre of mass
(or centre of gravity) is the balance point of the object (Millington, I. 2007). The centre of
mass of an object never changes as long as the object itself does not deform in any way. In turn,
this means an objects inertia tensor is also constant as long as the shape of the object remains
unchanged. Understanding the centre of mass helps to separate the dynamics into linear and
angular components. If the centre of mass is at the origin, equations are simplied signicantly.
The position of the centre of mass however can be calculated using the sum of all the particles
inside a rigid body.
c.o.m =
1
M

n
m
i
p
i
2.2 Position and Orientation
To calculate a rigid bodies output state, the initial position and orientation is important. The
position of a point on a rigid body from the origin in world space at time t can be described as
a translation vector x(t). Unlike a point, a rigid body is a volume of space, and has a particular
shape and mass. As a rigid body does not deform, a xed space called body space can be assumed.
We use the x(t) and R(t) values to transform body space into world space, as shown in Figure 1.
Figure 1: Transformation of body space to world space, taken from Bara, D. 2011
The rotation of a body can be described as a 3x3 matrix R(t). Position and orientation are the
spatial variable of a rigid body. (D. Bara, 2001). To calculate the position p(t) of a point on a
2
rigid body in world space, the position p
0
of the point in body space rst needs to be rotated about
the origin, and then translated, giving
p(t) = R(t)p
0
+ x(t)
Keeping the rotation of a body in a 3x3 matrix can encounter issues however, as calculations can
often result in a numerical drift, eventually resulting in a skewed rigid body. (Bara, D. 2001).
In three dimensions, an object has three variables for rotation: pitch, yaw and roll. These Eu-
ler angles represent rotations around the x, yand z axis respectively. Euler angles are not always
practical to implement into an application however, as applying local transformations result in a
movement of local axes.
Arguably, the best and most widely used method of rotations within applications is the implemen-
tation of quaternions.Quaternions are made up of four values, usually a scalar quantity and a three
dimensional vector. Quaternions not only take up less space than a rotation matrix - with 4 values
compared to 9 - but are easily normalised. This means that if skew does occur, it can easily be
xed. The unit quaternion Q(t) can be used to represent rotation rather than a rotation matrix.
It should however be understood that R(t) can still be used in other equations, but is not used to
track orientation. In this case,
R(t) =
_
_
p
xz
p
yx
p
zx
p
xy
p
yy
p
yz
p
xz
p
yz
p
zz
_
_
2.3 Linear and Angular Velocity
A rigid bodies motion can be split into two components - linear and angular velocity around the
centre of mass. Newtons second law of motion describes the velocity of an object depending on
the object and its mass. In rotation of an object, however, the angular velocity depends on torque
and the moment of inertia.
Linear velocity is simply the velocity of which the centre of mass is moving. The position and
orientation of a rigid body in respect to time is represented by x(t) and Q(T). If x(t) is the centre
of mass, then x(t) is the velocity of the centre of mass v(t). Therefore
v(t) = x(t).
(Bara, D. 2001)
To create an accurate simulation, it should also be noted how fast the object is rotating and
in what direction. If the position of the rigid body is xed, the body must rotate around the axis
through its own centre of mass. This angular velocity can be described as a three-element vector,
(t). The direction of this vector reveals the direction of the axis about which the body is spinning.
The magnitude of (t) reveals the speed of the rotation, and relates the angle through which the
body will rotate. Angular velocity is not as simple to calculate as linear velocity. If a body rotates
with angular velocity (t), then after time t the rotation of the body will be represented by the
quaternion
_
cos
|(t)|t
2
, sin
|(t)|t
2
(t)
|(t)|
_
3
At times t
0
+ t, the initial quaternion q(t
0
) should be rotated and then further rotated with a
velocity of omega(t
0
) for t in order to nd the orientation of the body. This gives
q(t
0
+ t) =
_
cos
|(t
0
)|t
2
, sin
|(t
0
)|t
2
(t
0
)
|(t
0
)|
_
q(t
0
)
Substituting t = t
0
+ t gives
q(t) =
_
cos
|(t
0
)|(t t
0
)
2
, sin
|(t
0
)|(t t
0
)
2
(t
0
)
|(t
0
)|
_
q(t
0
)
At time t = t
0
d
dt
cos
|(t
0
)|(t t
0
)
2
=
|(t
0
)|
2
sin
|(t
0
)|(t t
0
)
2
=
|(t
0
)|
2
sin0
= 0
and similarly
d
dt
sin
|(t
0
)|(t t
0
)
2
=
|(t
0
)|
2
cos
|(t
0
)|(t t
0
)
2
=
|(t
0
)|
2
cos0
=
|(t
0
)|
2
Thus, giving the relationship between angular velocity and orientation to be
q(t) =
d
dt
_
_
cos
|(t
0
)|(t t
0
)
2
, sin
|(t
0
)|(t t
0
)
2
(t
0
)
|(t
0
)|
_
q(t
0
)
_
=
1
2
(t)q(t)
2.4 The Moment of Inertia and Inertia Tensor
The moment of inertia is roughly described as the rotational equivalent of mass. (Millington, I.
2007). It is a measure of how dicult it is to change that objects angular velocity, and depends on
how the object is spun. There is potential for a dierent moment of inertia on each axis of rotation.
Unlike mass however, the moment of inertia cannot be represented as a single numerical value. All
the dierent values of the moments of inertia are displayed in a matrix called the inertia tensor.
The inertia tensor is a 3x3 matrix which is constant for each rigid body. Along the main diagonal,
the inertia tensor has x, y and z values of the moment of inertia. These values, I
xx
, I
yy
and I
zz
, are
the moments of inertia about their corresponding axis, through the centre of mass of the rigid body.
The remaining values are products of inertia, and use the distance of a particle from the centre of
mass of the object. Products of inertia can be roughly described as representing the tendency of
an object to rotate in a direction dierent from the direction in which the torque is being applied
(I. Millington, 2007, p. 199). As the products are a measure of symmetry, and values associated
4
with an axis perpendicular to a symmetrical plane will be zero. From lecture notes (MacTaggart,
D. 2013. pers. comm.), the inertia tensor in body space has a nal structure of:
I =
_

_
I
xx
I
xy
I
xz
I
xy
I
yy
I
yz
I
xz
I
yz
I
zz
_

_
2.5 Linear and Angular Momentum
The linear momentum P(t) of a rigid body is the sum of the products of the mass and velocity of
each particle. As the total linear momentum r of a particle with mass m and velocity v is known
to be p = mv, P(t) can be dened as
P(t) =

m
i
p
i
(t)
From the velocity p
i
of a particle, p
i
can be replaced for v(t) + (t) (p
i
(t) x(t)). Since a c.o.m
coordinate system is used,
P(t) =

_
m
i
v(t) + m
i
(t) (p
i
(t) x(t))
_
=

m
i
v(t)
= Mv(t)
Linear momentum represents the tendency for an object to remain in its current linear motion
(Van Val, J.M. et al. 2008). The faster the object is moving, the more force needed to change the
objects velocity. The conservation of momentum is extremely important for rigid body dynamics.
Newtons third law of motion is for every action, there is an equal and opposite reaction, therefore
forces within a system will always equal zero - so long as the the external force is 0. This means
that P(t) is constant, no matter how many objects are within a system.
Angular momentum is a dicult concept to grasp for a rigid body, but allows simpler calculations
than angular velocity. If a body is oating in space with no torque acting upon the object, the
angular momentum for that body is constant. However, even if a bodys angular momentum is
constant, this does not meant that the angular velocity is also constant. This uses the inertia tensor
as a scaling factor between L(t) and (t). From lecture notes (MacTaggart, D. 2013. pers. comm.),
the angular momentum of a body at time t is
L(t) = I(t)(t)
2.6 Force and Torque
The force acting on an object can be thought of as acting upon a certain point along an axis
through the centre of mass of an object. In order to change the momentum of a body, a force
must be applied. Force can be broken up into two main components - externals forces and internal
forces. Only external forces can translate or rotate an object. The relation beteween force and
linear momentum is : F = ma = m
dv
dt
=
dP
dt
, giving
F(t) =

P(t)
5
If a force is applied anywhere other than throught the centre of mass, a torque is also applied.
Torque (also known as moments of force) on a point depends on the location of that point
relative to the centre of mass. It can be thought of as a twisting force. Torque (t) is the derivative
of the angular momentum of a rigid body, giving
(t) =

L(t)
2.7 Constrained and Unconstrained Motion
Rigid body motion can roughly be dened as two types: Unconstrained and constrained motion.
Unconstrained motion deals with dynamic equations of the free motion of a rigid body. By free
motion, we mean that the motion is determined without worrying about collision detection and
response. (M. Coutinho, 2001). An unconstrained rigid body has three degrees of freedom to
translate and three to rotate along and about coordinate axes respectively.
Constrained motion arises when rigid bodies collide with one another and no inter-penetration
should be allowed. It handles computation of impulse and contact forces from collisions between
two or more rigid bodies. Constrained motion can also be applied to two or more rigid bodies
which are connected to limit their degree of freedom.
6
3 Application
3.1 Overview
The initial application was created to demonstrate user input on an object. This application will
create an unconstrained rigid body, and has been made using Unity.
3.2 Design and Implementation
The program was designed to include both a graphically based output so that the user could clearly
see what was happening, and a text based output for ease of viewing results of the mathematical
calculations that were done within the program. A simple application of a cube with no current
external forces applied was created.
The user is presented with an orange cube and dierent numerical outputs on the left hand side.
Figure 2: Cube at application start. User input box can be seen in the bottom right.
With a focus on user input, a text box is placed in the bottom right hand corner where the user is
able to input any value of force they wish to apply. The user can then click anywhere on the cube,
and a force shall be applied to that cube. Through this, a graphical implementation will show the
user how the cube should move dependant on where the user clicks. The closer the user clicks to
the centre of gravity, this case in the centre of the cube, the less the cube will rotate due to a lower
value of torque applied. Gravity will not be implemented in this application, to ensure no external
forces other than the force applied by the user interacts with the rigid body.
While the graphical representation is being shown, numerical values are displayed at the left of the
window. These are the main values which hand written calculations will be compared to, so as to
determine the accuracy of the rigid bodies implemented in the application.
The application should use classes to ensure tidy and easy maintainable code. With clear vari-
7
able names and well commented code, the application could be modied at a later date to include
the use of collisions and constrained rigid body motion.
The application has a text display with key values such as position from the origin and current
orientation in world space.
Linear momentum was calculated by taking the mass m of an object and multiplying each linear
velocity value stored in a Vector3 matrix by that number. For some simple representation of the
code implemented, only one value is shown here.
Box.velocity.x * Box.mass
Angular Momentum multiplies the inertia tensor and the angular velocity. Using built in Unity
functions.
Vector3 AngMo = Vector3.Scale(Box.inertiaTensor, Box.angularVelocity);
3.3 Results and Comparisons
A small selection of written calculations have been chose to show a comparison between results
from the application and the actual values which should be displayed. These show basic working,
and
Figure 3: Left: An example of output after a force has been applied. Right: Values which hand
calculations will be compared to.
3.3.1 Inertia Tensor
The application displays the inertia tensor as a Vector3 type (0.3, 0.3, 0.3). These are the principal
moments of inertia calculated in body space, in relation to the principal axes of inertia.
8
Initially, the inertia tensor was determined. The cube has a mass of 2, and is symmetrical with all
sides of length 1.
I
xx
=

m(y
2
+ z
2
)
=
1
2
_
1
2
dx
1
2
_
1
2
dy
1
2
_
1
2
(y
2
+ z
2
)dz
=
1
2
_
1
2
dx
1
2
_
1
2
(y
2
+
1
12
)dy
=
1
2
_
1
2
(
1
6
)dx
=
1
6
As the products of inertia are measures of symmetry, if a particular plane is a plane of symmetry
then the products of inertia of any axis perpendicular to the plane are zero, as shown here with
I
yz
=

myz
=
1
2
_
1
2
dx
1
2
_
1
2
dy
1
2
_
1
2
yzdz
= 0
The density of the cube is given by , and as mass = volume x density, = 2. Through symmetry,
it can be assumed that both I
yy
and I
zz
are also equal to
1
3
and I
xy
and I
xz
equate to 0. Therefore
giving the inertia tensor of the cube to be
I =
_

_
1
3
0 0
0
1
3
0
0 0
1
3
_

_
Once this was completed, the principal moments of inertia were derived from eigenvalues, giving
=
1
3
.


1
3
0 0
0
1
3
0
0 0
1
3

= 0
(
1
3
)(
1
3
)(
1
3
) = 0
=
1
3
9
These results show a slight round o in the program, displaying values such as 0.3 rather than the
full
1
3
.
3.3.2 Angular Momentum
In this instance, the angular velocity should be take to be = (0.6, 0.6, 0). The application shows
that this was the velocity of the object after applying a force of 50 in the forward direction at the
top right hand corner of the object. In turn, the application shows the angular momentum to be
(0.1, -0.1, 0). The angular momentum of a rigid body is said to be the cross product of the inertia
tensor and the current angular velocity. So at this point in time,
h = I
L =
_

_
1
3
0 0
0
1
3
0
0 0
1
3
_

_
_

_
0.6
0.6
0
_

_
L =
_

_
1
5

1
5
0
_

_
The application determines the angular momentum to be (0.2, -0.2, 0). Once again, the application
has rounded to one decimal place.
4 Conclusion
In conclusion, the rigid bodies in the application created are accurate enough to create a believable
simulation. Comparing the applications computations for values such as the inertia tensor and
momentum to hand calculated values, it can be noted that they are similar enough to be deemed
correct, only put o by rounding of the application to 1 decimal place. This could later result in
error through loss of data in calculations, but is suitable enough to be used for basic simulations.
References
Bara, D. 2001. Rigid Body Simulation. SIGGRAPH.
Coutinho, M. G. 2001. Dynamic simulations of multibody systems. Springer.
Lengyel, E. 2012. Mathematics for 3D game programming and computer graphics. 3rd ed. MA:
Course Technology Cengage Learning.
Millington, I. 2007. Game physics engine development. London: Morgan Kaufmann Publishers.
Van Verth, J. M. and Bishop, L. M. 2008. Essential mathematics for games & interactive appli-
cations: A programmers guide. Taylor & Francis US.
10

Вам также может понравиться