How do I find a unit vector of another in Java?

Posted by Shijima on Game Development See other posts from Game Development or by Shijima
Published on 2014-06-04T02:09:22Z Indexed on 2014/06/04 15:46 UTC
Read the original article Hit count: 167

Filed under:
|

I'm writing a Java formula based on this tutorial: 2-D elastic collisions without Trigonometry. I am in the section "Elastic Collisions in 2 Dimensions". Part of step 1 says:

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).

int[] normal = new int[2];
normal[0] = ball2.x - ball1.x;
normal[1] = ball2.y - ball1.y;

I am unsure what the tutorial means by dividing the magnitude of n to get the un.

What is un? How can I calculate it with my Java array?

© Game Development or respective owner

Related posts about java

Related posts about vector