### One-dimensional collisions

When two things collide in one dimension, their momentum is conserved.

That means the value of MA x VA + MB x VB remains the same at the beginning and at the end of the collision. This can also be written as
MA x VA1 + MB x VB1 = MA x VA2 + MB x VB2

In elastic collisions only, the kinetic energy is conserved.

This means the value of 0.5 x MA x VA x VA + 0.5 x MB x VB x VB is also the same at the beginning and at the end of the collision. This can be written as:
0.5 x MA x VA1² + 0.5 x MB x VB1² = 0.5 x MA x VA2² + 0.5 x MB x VB2²

With these two equations, we should be able to determine the final velocity of both things after the (elastic) collision.
So, starting off, we manipulate the momentum conservation equation.
can be shuffled around for similar masses on one side

The note above is for a shortcut that we are going to take in working the kinetic energy equation. I've highlighted the unknowns so that you don't lose them in the steps that we're following. Next comes the kinetic energy equation:

Now the momentum equation that we have so far can be further massaged into an expression for va2.

Finally, we have the value for the second object's final velocity. Putting this into the kinetic energy equation will give us the value for the first object's final velocity.

So, using these formulas, you can find the final velocity of the two objects undergoing an elastic collision.

### Two-dimensional collisions

The above equations hold for a few specific instances. Particularly, it holds for completely head-on collisions.

The formula can be split to describe each dimension in any collision in which one sphere hits the other directly (along the center of mass).

It does not hold for collisions in which one sphere hits the other at an angle, which is most collision are in 2D.

This is where we have to employ some 2D vector math to describe the final velocities and angles of each sphere. First of all, let's assume that each sphere has a velocity that is expressed as a vector. So, sphere A will have a velocity of [Vax, Vay] and sphere B will have a velocity of [Vbx, Vby].

The collision direction (the segment connecting the centers of the two spheres) is some angle. The value of this angle is shown below:

Of course, with a vector and an angle, there are two components: one that is along the angle, which is |vector| * cos(angle), and the other that does not touch the angle, which is |vector| * sin(angle). Keep that in mind.
Now, in a collision like this, the part of the velocity that is perpendicular to the gold line (we're going to show this in the below picture) would fit with the one-dimension formula that we (not so) laboriously derived above. The portion that is parallel to the gold line remains unchanged during the (elastic - reminder) collision.

Now, as you can see, the whole scene is rotated. This means the velocity vectors have now been rotated at the angle from the horizontal and will each have components in the horizontal and vertical direction. Let's get rid of the Va and Vb vectors now since we don't need them - the four blue components explain the velocity fully.

There are now 8 vector components (magenta in the picture). Their values are easy to find; we only need to use trigonometry to find the values. I explained the shortcut above, "If the component touches the angle, it is length * cos(Angle), otherwise it is length * sin(Angle)".
The values of the 8 component vectors are:
 Vaxg = Vax * Cos(Angle) Vaxh = Vax * Sin(Angle) Vayg = Vay * Sin(Angle) Vayh = Vay * Cos(Angle) Vbxg = Vbx * Cos(Angle) Vbxh = Vbx * Sin(Angle) Vbyg = Vby * Sin(Angle) Vbyh = Vby * Cos(Angle)
For simplification purposes, we'll express these 8 vectors into 4 vectors as shown in the following picture.

In this case, each component is the sum of two of the old magenta components. The values of each term are:
 Vag = Vaxg + Vayg = Vax * Cos(Angle) + Vay * Sin(Angle) Vah = Vaxh + Vayh = Vax * Sin(Angle) + Vayh = Vay * Cos(Angle) Vbg = Vbxg + Vbyg = Vbx * Cos(Angle) + Vby * Sin(Angle) Vbh = Vbxh + Vbyh = Vbx * Sin(Angle) + Vbyh = Vby * Cos(Angle)
Note that all of these terms are now known. The value of Angle is again .

As mentioned earlier, the velocities that are perpendicular to the collision direction are unchanged during the collision. So, Vah and Vbh are not to be changed.
The final values of Vag and Vbg are going to be determined by the one-dimensional collision formula that we found above:

Putting in our values: Vag in place of Va1 and Vbg in place of Vb1, we can now find the final velocities in this direction of collision.

The picture below illustrates our new situation.

Now, all we need to do is spin the scene back to where the images collided at the original angle.

In this new scene, which is remake of the old scene, we again have 8 vector components. We can first find these components' values by using trigonometry and the same shortcut we used to find those 8 magenta components. The blue components are:
 Va2x = Va2 * Cos(Angle) Va2y = Va2 * Sin(Angle) Vahx = Vah * Sin(Angle) Vahy = Vah * Cos(Angle) Vb2x = Vb2 * Cos(Angle) Vb2y = Vb2 * Sin(Angle) Vbhx = Vbh * Sin(Angle) Vbhy = Vbh * Cos(Angle)
And again, we can combine pairs of these into one vector so we only have four vectors. These four vectors will be the sole vectors that determine the outcome of this whole problem. This is what we are looking for!

So, our final values are:
 Vxa = Va2x - Vahx = Va2 * Cos(Angle) - Vah * Sin(Angle) Vya = Va2y + Vahy = Va2 * Sin(Angle) + Vah * Cos(Angle) Vxb = Vb2x - Vbhx = Vb2 * Cos(Angle) - Vbh * Sin(Angle) Vyb = Vb2y + Vbhy = Vb2 * Sin(Angle) + Vbh * Cos(Angle)
Our final results, in terms of Vax, Vay, Vbx, Vby, and Angle from the original picture:

are:

That's only one. The other three I can shortcut from this one:

Vya is merely switching the cos with sin and changing the negative on the outside to a positive.
Vxb can be shortcut by exchanging every A with B and B with A. If you've noticed, all of the above calculations fall into this pattern.
Vyb can be shortcut similar to how Vya is shortcut.