Pregunta

I'm reading a book on building a physics engine. I am currently stuck on nonlinear projection, which is a way to resolve penetration between Rigidbodies, because I don't fully understand the code.

Here is a brief description to the best of my understanding. Nonlinear projection is more believable than linear projection because it adds rotation to linear projection. The book uses this algorithm:

  1. calculate the total inertia. there is linear inertia, which is the object's inverse mass, and there is angular inertia, which is calculated from the object's moment of inertia.
  2. move each object linearly, along the contact normal ( a vector ) proportional to the linear inertia. That would be [ contact normal vector ] * penetration * ( linear inertia ) / ( total inertia )
  3. rotate each object proportionally to the angular inertia. That would be [ some rotation direction ] * penetration * ( angular inertia ) / ( total inertia )

Linear inertia: I fully understand the linear inertia part.

Angular inertia: The book calculates the angular inertia of an object using the following algorithm, which I do not understand, because it gives no explanation and assigns every step to the same variable, angularInertiaWorld.

  1. determine the relative contact position, which is the location of contact ( as a vector ) minus the location of the center of mass ( another vector ), or the position, of the object. therefore, the relative contact position is relative to the object.
  2. do this math: (relative contact position) (crossproduct) (the contact normal). the contact normal is the vector perpendicular to the surface of the contact.
  3. transform what you got in step 2 by the inverse inertia tensor of the object to convert the result of step 2 into world coordinates
  4. do this math: (result of step 3) (crossproduct) (relative contact position)
  5. do this math: (result of step 4) (dotproduct) (contact normal)

I'm wondering what's going on in each step of the algorithm. All I can figure out is you start with some values and you end up with a value that's supposed to be the angular inertia of the object.

Linear projection: I fully understand the linear part of the nonlinear projection algorithm.

Angular rotation: The book uses this algorithm to calculate by how much to rotate the object. There are a few more meaningful variable names here, which helps me understand things a little more.

  1. calculate an impulsive torque, which I believe is the amount of rotation generated from a unit of impulse. this is calculated by doing (relative contact position) (crossproduct) (contact normal)
  2. calculate the amount of impulse required for 1 unit of movement. this is done by transforming the impulsive torque by the inverse inertia tensor.
  3. calculate the amount of rotation per unit of movement. this is done by dividing the impulse per unit of movement by the angular inertia.
  4. calculate the amount by which you want to rotate the body. this is done by multiplying the amount of rotation per unit of movement ( a vector ) by ( amount of penetration ) * ( angular inertia ) / ( total inertia ).
  5. the amount by which to rotate is added to a quaternion, which I have understood.

I get all the unit analysis and the impulse stuff the book does to get to a rotation amount. What I don't quite grasp is the usage of the inverse inertia tensor.

Maybe I haven't been fully understanding that. I had originally thought that it was just like the scalar moment of inertia of an object and used in torque = I * alpha, where I is moment of inertia and alpha is angular acceleration. Then, when you apply a torque, you get alpha = torque / I so multiplying torque by the inverse moment of inertia would get you alpha. As a result, I thought that was what the inverse inertia tensor was for.

I would appreciate it if anyone could explain to me how it's being used here.


Finally, thank you for taking the time to read through all that. I would really appreciate any explanations on the angular inertia and/or angular rotation parts.

¿Fue útil?

Solución

As to angular inertia:

In this algorithm you compute the change in velocity as a response to the force normal to the surface of the object (contact normal vector is the normal force vector):

step 2: (relative contact position) x (the contact normal [force]) = (moment of inertia)

step 3: (inverse inertia tensor) applied to (moment of inertia) = (angular velocity)

step 4: (angular velocity) x (relative contact position) = (linear velocity)

step 5: (linear velocity) * (the contact normal [force]) = change in velocity in the direction of the applied force

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top