add a length to all values of a 3d vector
Community Forums/General Help/add a length to all values of a 3d vector
| ||
Hello, If i want to add the length 0.25 to all values of a 3d vector (i mean on x, on y, on z) so that the total length of the vector is equal to length + 0.25 I don't think it is as simple as doing : VectorX = VectorX + 0.25 VectorY = VectorY + 0.25 VectorZ = VectorZ + 0.25 because if i do this the vector may change its direction and its length... So i suppose i have to normalize the vector, then multiply the normalised values by 0.25, then add the result to the initial values of the vector ? So it would be : NormalisedX = VectorX/Length NormalisedY = VectorY/Length NormalisedZ = VectorZ/Length AddX = NormalisedX * 0.25 AddY = NormalisedY * 0.25 AddZ = NormalisedZ * 0.25 VectorX = VectorX + AddX VectorY = VectorY + AddY VectorZ = VectorZ + AddZ Yes ? No ? What do you suggest ? Thanks, |
| ||
If the goal is same direction and add 0.25 to length then you need scale = (oldlength + 0.25) / oldlength and then multiply x,y,z by scale. |
| ||
@Floyd>>This makes sense, thanks ! |
| ||
Just a quick point. .. if your vector is aligned with an axis you can do it very easily without any normalisations. |