#### Archived

This topic is now archived and is closed to further replies.

# Reflecting linear velocity off surface easy, angular not so much...

This topic is 5540 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi I'm sure many of you know how to reflect an objects linear velocity off of a surface... It involves getting the dot product of the normal and the velocity, and then subtracting from the velocity a vector in the direction of the normal with size (dot product * 2)... This is all well and good, but what about when you have a rotating object that rotates into a surface? is there an easy way to kind of 'reflect' the angular velocity? The angular velocity is stored as a vector. The magnitude being the amount of radians to rotate and the direction being the axis around which to rotate. So, given the point on the surface, the surface normal, and the angular velocity, how would one get the new angular velocity? Thanks for taking the time to read this... Any help appreciated [edited by - nexius on August 16, 2003 12:47:46 AM]

##### Share on other sites
this is a lot more complicated than just velocity reflection. If you use proper dynamics, with forces and impulses, it involves the inertia tensor.

All I can give you is the equation for calculating the impulse generated at the point of contact.

Ra = (Pa - O)Va = V + (W x Ra)Impulse = [ -(1 + e) * (Va . Na) ] / [ 1/Mass + Na . (InvInertia * (Ra x Na)) x Ra]Force  = Impulse / dtTorque = (Ra x Impulse) / dtV'' = Force  * (1 / Mass)W'' = Torque * InvInertiaV += V'' * dtW += W'' * dtO += V * dtA += W * dt

V : linear velocity of the box
W : angular velocity ofd the box
O : centre of the box
A : angle of the box

Mass : mass of the box
InvInvertia : inverse inertia of the box
Pa : Point of contact
Na : normal at point of contact
e : elasticity of the box (how much it ''bounces'', in range [0, 1])
Va : velocity at the point of contact
Ra : position of the point of contact relative to the centre of the box
dt : Physics timestep
Force : Force of the collision
Torque : Amount of torque generated by the collision
V'' : linear acceleration of the object
W'' : rotational acceleration of the object.

the inertia tensor for a box of extents (or called half-size) (dx, dy, dz) is

x2 = (dx * dx * 4.0f);y2 = (dy * dy * 4.0f);z2 = (dz * dz * 4.0f);ix = (y2 + z2) / 12.0f;iy = (x2 + z2) / 12.0f;iz = (x2 + y2) / 12.0f;    | ix  0  0 |I = |  0 iy  0 |    |  0  0 iz |

the inverse inertia matrix is the transpose of the inertia matrix

I'' = Inertia.Transpose()

the body''s inverse inertia, as the body rotates in the world becomes then

InvInertia = Orientation * (I'' * 1/Mass) * Orientation.Transpose()

so, I'' and I inertia tensors are constant, and depends only on the shape of the object. On top of that, the InvInertia also depends on the current orientation of the object and the mass of the object.

all those equations work also for body vs. body collision, not just body vs. environment, but you need to extend the impulse calculation a little, to take into account the other object''s properties.

Also, one more thing. I tried using the angular velocity, as you did, with taking the angular velocity direction as an axis of rotation, and the magnitude as the rotation angle, but couldn''t get a decent result. I had to revert to a special equation that converts the rotational velocity into a quaternion, and does some euler integration on quaternions, then use that quaternion and turn it into a matrix to get the orientation matrix. That works. Anyway, try it.

##### Share on other sites

I''m struggling to understand how that works though.

The equation for impulse you gave appears to work out as a scalar, and yet it looks like you''re doing a cross product between it and Ra when calculating the torque, which confuses me...

Impulse = [ -(1 + e) * (Va . Na) ] / [ 1/Mass + Na . (InvInertia * (Ra x Na)) x Ra]

Could you explain where I went wrong?

Thanks

##### Share on other sites
Is it just in the same direction as the normal?

##### Share on other sites
sorry, yeah. the impulse vector if Impulse * Normal.

doing rotational stuff increase the complexity of the physics system by quite a lot. For example, if you do collision detection using swept boxes, due to a rotation between frames, the boxes could become entangled, which is a pain.

And you have to deal with inertia, and converting rotational velocity to a rotation matrix, and solving multiple contacts becomes a necessity (or you''d get things like a box endlessly tip-toeing on a plane, as the point of contact switches from one corner of the box to another, due to contact impulses making the box rotate). Quake and most first-person-shooters, don''t bother with rotations. The volumes are all axis aligned, and grenades and projectiles are just particles or small axis-aligned boxes.

The plus point with using rotations and a full-on physics system, you can use proper fricitonal forces, ragdolls and joints. It brings a lot of freedom to the engine, but it''s alot of work (and contact solving can be computationaly expensive).

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632959
• Total Posts
3009463
• ### Who's Online (See full list)

There are no registered users currently online

×