# Rotate an objects velocity

I have a collision system (in 3D but for the purpose of the question assume 2D) where I want to calculate the new velocity (stored as a vector) after a collision.

What I have is the velocity of the object colliding against a plane and I want the object to then slide down that plane.

I know the angle of impact with the plane and I know the normal of the plane. I can create a Rotation Matrix for the rotation that the velocity needs to be changed by, I just am not sure how I rotate the velocity vector by that matrix.

I'm sure it's an easy answer but I haven't quite been able to get it.

I added a picture as requested

Any help would be appreciated.

• Can you add images? It would help to visualize exactly what you're trying to achieve -- It's kinda ambiguous and I didn't get just by reading, sorry. – Gustavo Maciel Jun 2 '15 at 10:39
• @GustavoMaciel no prob, I added a picture - please just say if it doesn't make sence. – unknownSPY Jun 2 '15 at 11:20

You don't need to rotate the velocity at all.

Get the velocity Magnitude, get the new direction, bring the two together. The new direction is the hardest part. Probably you want it a perpendicular vector to the plane normal, but now you have infinite perpendicular vectors to the plane normal. The easiest answer may be get the one going down, since you just said you want to slide "down".

Vector3 Length() {
return sqrt(x*x + y*y + z*z);
}
Vector3 Cross(Vector3 a, Vector3 b) {
return new Vector3(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x);
}
float magnitude = oldVelocity.Length();
Vector3 newDirection = Vector3.Cross(plane.Normal, Vector3.left);
Vector3 newVelocity = newDirection * magnitude;


This should do.

But just in case you REALLY want to know how to transform a vector by a matrix, then just read this: http://blog.wolfire.com/2010/07/Linear-algebra-for-game-developers-part-3

• Thanks, am I right in thinking that for the calculating the newDirection when working in 3D, if the plane normal is Vector3(1.0f,0.0f,0.0f) and the plane is in the Z plane I can just use "up" (Vector3(0.0f,1.0f,0.0f)) as my "left" vector? – unknownSPY Jun 2 '15 at 11:56
• @unknownSPY bear in mind that the cross product returns the perpendicular vector. The perpendicular vector between (1, 0, 0) and (0, 1, 0) is (0, 0, 1). That is, if your up is (0, 1, 0) that is, you'll have forward returned. You might want to really pass left or right as the second vector, since the only remaining direction will be up or down. – Gustavo Maciel Jun 2 '15 at 12:00
• @unknownSPY also: by Left or Right I mean relative to the plane. Since your plane is already pointing right, you might want to use (0, 0, 1). – Gustavo Maciel Jun 2 '15 at 12:02