Monday, November 29, 2010

Movement post-collision

Currently I have two factors that influence physical motion of objects. The first is gravity (-9.8m/s2) and the second is a collision with another object. Implementing gravity is easy  subtract (9.8 ĵ * t) from an object's velocity every t seconds (t being defined as the time between frames).

Telling an object how to move after a collision has been detected between it and another object, however, is a bit more involved. When an collision is detected, the program notes between which two objects it has occured as well as the point of collision (a separate value is tracked for each object - one for each reference frame). In the diagram below, the rectangle is colliding with the ground at its bottom right vertex.

As a result, the center of gravity will continue to move downward, but the vertex will move up. The relative angular velocity ω is incurred as a direct result. But how do we get that angular velocity? Why, by way of trigonmetry, of course!

In equation (1.), we see the plain definition for ω as being the ratio of the magnitudes of the tangential velocity to the radial vector. But, we need that tangential velocity. We can get that as being the tangential component of the velocity of the center of mass, as is then therefore defined as the magnitude of that velocity times the cos of an angle θ, as seen in the diagram above and in equation (2.). But to calculate this, we need θ. Luckily, that's easily obtained as seen in equation (3.).

Substituting for θ, equation (2.) simplifies to equation (4.), and substituting for vT, equation (1.) simplifies to equation (5.). Phew!

Now that we have our angular velocity, we need an axis about which to rotate the object. That's a simple cross product of the radial vector and the velocity vector (in the first diagram, it points out of the screen at the center of mass). Voila!

Implementation should hopefully be tonight.

No comments:

Post a Comment