
426 Chapter 16 Stability and Optimization
different times, depending on their mass. To avoid this, we remove the masses from
the expression to get the following:
motion =|
˙
p|
2
+|
˙
θ |
2
In code, this looks like:
currentMotion = velocity.squareMagnitude() + rotation.squareMagnitude();
Some developers use variations on this: they either add the two components
together without squaring them, or they calculate the full kinetic energy and then
divide by the mass. In either case, this gives us a value for the motion of the object.
The final stage is to chec k whether this value is stable. We do this by keeping a record
of the current motion over several frame ...