Graphics Reference
In-Depth Information
Recall that the net force on a system is written f ( t , y , v ) . If we were consider-
ing a single body, then it would have its center of mass be at point y and linear
velocity v . In terms of our position function x , we can and often will apply the
force function as f ( t , x ( t ) , x ( t )) . As previously discussed, we make the position
and velocity explicit arguments distinct from x because that is the form of the
function when incorporated into a dynamics solving system.
Forces always arise between a pair of objects. By Newton's third law of
motion, both objects in the pair experience the force with the same magnitude
but in opposing directions. Thus, it is sufficient to describe a model of the force
on one object in the pair. Likewise, one need only explicitly compute the force on
one object in the pair when implementing a simulator. In a system with multiple
bodies, the y and v arguments are in arrays of vectors, and the net force function f
computes the force on all objects, due to all objects.
For n bodies, there are O( n 2 ) pairs to consider. Forces combine by superpo-
sition, so the net force on object 1 is the sum of the forces from all other objects
on object 1. This means that the general force implementation of the force func-
tion looks like Listing 35.2, where the pairwise force F (t, y, v, i, j) function
computes the force on the object with index i due to the object with index j . There
will be many kinds of forces, such as gravity and friction, so we consider an array
of numForces instances of F .
Listing 35.2: Naive implementation of the net force function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Net force on all objects
Vector3[n] f (float t, Vector3[n] y, Vector3[n] v) {
Vector3[n] net;
// for each pair of objects
for (int i = 0; i < n; ++i) {
for (int j = i + 1;j<n;++j) {
// for each kind of force
for (int k = 0; k < numForces; ++k) {
Vector3 fi = F [k](t, y, v, i, j);
Vector3 fj = -fi;
net[i] += fi;
net[j] += fj;
}
}
}
return net;
}
One would rarely implement the net and pairwise force functions this gen-
erally. In practice many forces can be trivially determined to be zero for a pair.
For example, the spring force between two objects that are not connected by a
spring is zero, gravity near the Earth's surface can be modeled without an explicit
ball model of the Earth, and gravity is negligible between most objects. Other
forces only apply when objects are near each other, which can be determined effi-
ciently using a spatial data structure (see Chapter 37). Many of the pairwise force
functions don't require all of their parameters. Taking these ideas into account, an
efficient implementation of the net force function for a system with a known set
of kinds of forces would look something like Listing 35.3.
 
Search WWH ::




Custom Search