# Setting a vector to another magnitude

1. Jul 19, 2009

### wraithseeker

When you set it, initially I have to do

length = Sqrt(x*x+y*y*z*z)
length = newlength/length
set all the velocities to multiply by length

I am wondering what is this for?

length = newlength/length

2. Jul 19, 2009

### CompuChip

newlength/oldlength is the fraction by which the length has to increase. The length of the new vector will be
|| oldvector * newlength / oldlength || = || oldvector || * newlength / oldlength = oldlength * newlength / oldlenght.

Alternatively, you can look at it this way: if you have a vector v, first divide it by its length to make a unit vector u (in the same direction but with length 1). Then multiply u by the length you want it to have to get the new vector:
v' = u * newlength = (v / oldlength) * newlength = v * (newlength / oldlength)
where oldlength is the length of v (sqrt(x^2 + y^2 + z^2)).

3. Jul 19, 2009

### flatmaster

Well, you're talking about a vector, so I assume direction is important. It would be easier to change leingths of individual cartesian components by the desired amount. In cylindrical and sphercal, you merely change r.