# Physics

This week in computer science, we talked about physics.

Our universe is governed by certain physical laws. Luckily for us, those laws are predictable, mathematical, and general. That means that we can create simulations that mimic physics with relative ease. So how does one go about making a physical simulation?

### Level of Detail

Some simulations need to be more precise than others. For a videogame, you only need to be within a few pixels of real motion. For a subatomic particle simulator, you need to be precise out to the number of decimal places that your real-life equipment uses. This is important, because everything that I am about to describe is an approximation.

Real physical laws happen in continuous time. Computers can only do a discrete amount of work in finite time. So the first corner-cutting measure we need to fit physical laws into our limited machines is this:

1. Have the computer take the current state of a system
2. Project that system a finite, but small, time into the future
3. Repeat

For example, if you are trying to determine the motion of a falling body:

1. Add the velocity*deltaT to the position
2. Add the acceleration*deltaT to the velocity
3. Repeat

This is a very good approximation for reality, but not quite perfect. This is because position and velocity change in fluid curves, while this approach approximates them with a number of straight line segments. As deltaT approaches `0`, the approximation gets better, but it will never be perfect.

The next thing that often gets cut in physics simulations is realistic collisions. In the real world, collisions are very complicated interactions, with both objects flexing slightly, and the internal components of those objects jostling around. For computer simulations, it’s often enough to simply detect whether two objects are touching, and then reflect their velocities across the plane of impact.

Games have gotten better at handling collisions in recent years, however, by introducing a ‘rag-doll’ model that allows parts of players and monsters to move independently.

Finally, because of the inaccurate approach to motion and collisions, the other issue that physics engines have to deal with is when one object accidentally ‘clips’ inside another. This is of particular interest in games, because if players can arrange the physics just right to clip through a wall, they can subvert many of a game’s challenges.

Clipping is more a result of inaccuracy in simulators, than a cause of it. Still, handling clipping is important to ensure that your simulator doesn’t allow the impossible.

That’s all for this week. This will be my final article on computer science this term - there is only one class left before finals. I hope you enjoyed CS 417 - From Programs to Computer Science