Physics - Programming Techniques

Here we discuss some of the practical issues and techniques required to model physics.

see also this page about computer animation using physics.

We are never going to get 100% accuracy, unless we simulate every atom, even then there are certain situations where our results are very sensitive to the starting conditions. In these cases we can tip over from a stable situation to chaos, however many of the practical real world things that we will be modeling are setup in such a way that they can be reasonably stable. Although a sequence of multiple collisions will often produce very difficult outcomes depending on minute changes to the starting conditions.

So we must carefully choose between the various techniques. Our choice will depend on what we want to do, what computing resources we have, how much complexity we will accept, and so on.

Real Time verses Offline

Programs which model physics, like games and simulators, often need to output a sequence of pictures of the animation. If we are producing a moving animation offline then we can afford to use more computativley intensive techniques to produce a more accurate result, we can also use a constant time step and make that time step as short as we need. With real time games or simulations we need to make more compromises also if there is more happening the frame rate may go down and so we need to be able to cope with variable time steps so that the speed of objects is not varied making them appear jerky.

Numerical versus Analytical

When we are solving these problems by hand we tend to represent the situation with a set of equations, if we can solve these equations (which may be impossible for 3 or more bodies), we can use them to predict the position of objects at any time. That is, until we get to a discontinuity such as a collision, we need to detect and calculate the response to these collisions. We then need to derive a new set of equations for the colliding objects and continue. (the practical issues involved with calculating collision responses is described on this page)

This technique is difficult (although not impossible) to automate. It is often essay to trade of this analytical complexity for numerical complexity which can be more easily handled by computers. This can give more accurate results in some ways but less accurate results in other ways as described in the two sections below:

Solid body versus Finite Element Methods (quantze space)

Finite Element Methods can model deformable shapes much more easily. We divide the solid body up into regular shapes such as cubes, we can then represent the compression or expansion of each cube and model its interaction with the cubes around it. This requires a lot of calculations but it is the sort of thing computers can do reasonably easily given enough time. Within an object the link with the cubes around it is permanent but during a collision or contact with another object then links have to be setup dynamically as required.

This allows us to model deformable shapes more accurately but, of course, there will always be errors due to the finite size of the cubes.

Integration versus Equations (quantize time)

We can specify the dynamics in terms of differential equations with respect to time or, by integrating both sides of the equations, we can express them as an integral of time. This allows us to calculate the state at time t+Δt from the state at time t.

step

Therefore we can build up the animation where each step is derived from the previous one.

The finite size of this time step will cause inaccuracies as the animation proceeds. In most cases these will be small and possibly cancel each other out but in other cases this leads to real problems. For instance, if we have a moon orbiting a planet and if we take the case where this orbit is circular, then this is easy to calculate using a formula and we can calculate the positions indefinitely without any problems. But if we use a finite time step method then the errors will gradually add up and the moon will deviate from its orbit.

Forces and Impulse

All changes of motion involve an exchange of momentum between two or more objects. Momentum is exchanged by means of forces, if we take the limit as a force approaches infinity but its duration approaches zero then we call this an impulse.

When simulating this in a program we may choose to:

There are advantages in treating gravity and collisions in the same way to simplify our programs and make them more robust.

If we use forces for everything we assume that collisions happen over a finite time rather than instantaneously, this can be more accurate and we have the simplification of dealing in pure forces, typically we would use 'penalty' methods to do this. That is when two objects intersect we use such factors as penetrating depth or volume to calculate the resulting force. To do this requires a lot of modeling detail in time and space intervals otherwise objects could have passed through each other before the forces take effect.

You may be surprised that we would consider using impulses for force fields such as gravity but, as discussed above, we probably need to quantise time so it does make some sence having a step change of momentum between these time increments.

Spring models

see this page.


metadata block
see also:

 

Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

flag flag flag flag flag flag New Foundations for Classical Mechanics (Fundamental Theories of Physics). This is very good on the geometric interpretation of this algebra. It has lots of insights into the mechanics of solid bodies. I still cant work out if the position, velocity, etc. of solid bodies can be represented by a 3D multivector or if 4 or 5D multivectors are required to represent translation and rotation.

 

Commercial Software Shop

Where I can, I have put links to Amazon for commercial software, not directly related to the software project, but related to the subject being discussed, click on the appropriate country flag to get more details of the software or to buy it from them.

Matlab.

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2015 Martin John Baker - All rights reserved - privacy policy.