Complex Collision Engine
Single Dimension Collisions
It may be tempting to try to jump right into creating a nice, functional 3D collision engine but it is important to know the
basics before progressing. That is why we should start with one dimensional collisions, they are simple enough right? The
whole point of this collision engine is to be physically realistic so we need to give our particles physical properties. The
first property will come in handy, mass. Mass is the measure of resistance to inertia change and does not change unless an
object physically changes, ex. fragmenting. Our particles will be assumed to be non-deformable and infinitely durable. The
next property of our object will be side length, in order to show the effects of mass in the collision engine the side length
is related to the particle's mass under this equation:
$$length = {10 * \sqrt{mass}}$$
The constant multiplier 10 is used to scale the particles to reasonable sizes in the drawing canvas and the reason I chose
the length to be directly related to the square root of the mass was so that the particle's area is directly related to the
mass of the particle. Another property of the particles is the color of the particle, there is no significant meaning behind
the colors choosen. That concludes the summary of the constant aspects of a particle. Because this is a single dimensional
collision engine, the particles will only require two non-constant properties, position (X) and velocity. This is where things
begin to get interesting.
Understanding the Simulation
Before explaining the calculations, let's understand how our simulation works. The simulation displays our scene by first
initializing all particles with their initial values and constants. This includes things such as setting mass, color, initial
velocity, etc. Upon successful initialization the simulation will begin animating the scene. To do this the simulation will
draw all the visible particles onto the drawing canvas using the information which it just initialized. From now on I will
refer to this as drawing a frame. After drawing the initial frame the simulation will proceed to update the data from the scene
before drawing a new frame to the screen. So, what you are seeing on the screen is not a continuous video but rather the
projection of many frames one after another.
While drawing frames is what allows us to see what the simulation is rendering, it does not control how our particles interact.
This is controlled by the simulation in the time between two frames being drawn, when the simulation is updating the scene.
Updating the data after each frame is where our collision engine comes into play. Each frame is associated with a culmination
of data related to the scene called a data packet. Our collision engine will be given a record of this data packet as well as
the time which has elapsed since the last frame was drawn, hence the engine must update the data by that much time into the future.
Particle Physics
The collision engine will be responsible for calculating the appropriate physical changes in this time period. To start, we must
consider how a particle changes over time. During a period of time a particle can either move freely or it can collide with
something else in the scene.