Page 1 of 1

Speed of object

Posted: Sun Mar 20, 2011 12:42 am
by cookie
I've got a vector which contains the speed of an object on the X,Y and Z-Axis. How can I get the "absolute" speed of this objects by using the X Y and Z Speed of it?

Posted: Sun Mar 20, 2011 1:04 am
by Seven
I am not sure what you mean. can you give an example of what you are trying to do?

Posted: Sun Mar 20, 2011 1:23 am
by DarkDepths
I think you mean that you want to know the magnitude of the vector (ie the "length" of the line from your current position to the one indicated by the vector)?

Doing that, if I remember my math correctly, is fairly simple. Just square all the values, add them together, and then take the square root.

sqrt( x^2 + y^2 + z^2 )

For example, x = 2, y = 3, z = 4:

sqrt ( (2)^2 + (3)^2 + (4)^2 )
= sqrt( 4 + 9 + 16 )
= sqrt( 29 )
= ~5.4


Is this what you were looking for?

Posted: Sun Mar 20, 2011 1:32 am
by Seven
vector3df.getLength()? seemed to easy........

//! Get length of the vector.
T getLength() const { return core::squareroot( X*X + Y*Y + Z*Z ); }

Posted: Sun Mar 20, 2011 1:40 am
by DarkDepths
Seven wrote:vector3df.getLength()? seemed to easy........

//! Get length of the vector.
T getLength() const { return core::squareroot( X*X + Y*Y + Z*Z ); }
Oh, haha. I figured there would be a function for it. Looks like i'm still retaining my math fairly well though :P

Posted: Sun Mar 20, 2011 2:46 am
by cookie
Yeah, thats what I was looking for.

Thanks :)