Elastic Collision Formula in Java
- by Shijima
I'm trying to write a Java formula based on this tutorial: 2-D elastic collisions without Trigonometry. I am in the section "Elastic Collisions in 2 Dimensions". In step 1, it mentions "Next, find the unit vector of n, which we will call un. This is done by dividing by the magnitude of n".
My below code represents the normal vector of 2 objects (I'm using a simple array to represent the normal vector), but I am not really sure what the tutorial means by dividing the magnitude of n to get the un.
int[] normal = new int[2];
normal[0] = ball2.x - ball1.x;
normal[1] = ball2.y - ball1.y;
Can anyone please explain what un is, and how I can calculate it with my array in Java?