 # Unitize (vectors)

What is the Unitize function? Can a simple example?

1 Like

It makes a vector of ANY length to have the length 1 unit. (whatever unit).

This is very useful when you care only about the direction, and you know the distance from other data. Then unitize you vector and multiply it with your (otherwise known length) and then you have have a vector with both the directiona dn the length you wanted.

``````// Distance between some points of arbitrary distance, but representing
// the useful direction we want
Vector3d v  = SomePoint - SomeOtherPoint;

// Resizes the vector to the length = 1
v.Unitize();

// I want to go one hundred meters in that direction:
v = v * 100; // same as; 1 * 100 = 100
``````

Now the vector “v” points in the right direction and with a length that gets you that distance of one hundred meters.

// Rolf

3 Likes

The only thing that I would add to @RIL’s great explanation, is that unitizing a vector is mostly referred to as “normalising the vector” in mathematics. The resulting vector is called “unit vector” and has a length of 1.
You can calculate the unit vector by diving all of its components/coordinates by its length, which most certainly is what the Unitize() method does internally.

2 Likes

Thanks to all!