Original Post
Hi I am trying to build a Rigid Body Simulator. So far I have my vehicles moving using the rigid body dynamic equations. I was trying to incorporate the collision response for these vehicles. While I can easily implement a linear collision response ( ie treat rigid body as a particle , so when the bodies collide they just go in different directions based on coefficient of restitution). I am having trouble implementing the angular affects of collision response. I.e. when the bodies collide they also spin in the appropriate direction as well as going in different direction. This looks a lot more appealing and a true indicative of rigid body structure. The algorithm for collision detection is as follows: - Procedure Check for collision { • Do a quick circle bound exit check to see if the two bodies are coming towards each other. • Check for vertex- vertex collision. Store the collision normal and relative velocity • Check for vertex-edge collision. Store the collision normal and relative velocity • Check if there is interpenetration ( using point in triangle) algorithm End The driver algorithm which calls this collision detection algorithm is as follows: - Procedure Simulation Increment { while (there is a collision or no-collision) • Update Body1 physics by ‘dt’. • Update Body2 physics by ‘dt’ • Check for collision between Body1 and Body2. • If there is inter-penetration • Divide dt by half • If ( there is a vertex-vertex or vertex –edge collision) • Apply Impulse to the linear and angular velocity of Body1 • Apply -Impulse to the linear and angular velocity of Body2 • EXIT } The driver for this algorithm checks for every cycle after updating the body’s physics if there is any collision. If there is interpenetration, it backs up time ( ie divides the time by half ) and updates the physics based on the new time in hopes to find the exact time when collision/no collision is taking place. Ie the point is that if there is inter-penetration it divides time by half each time, updates each body’s physics and thus backs up until we have a collision or no collision. Thus the driver assumes that the two bodies are not inter-penetrating initially. Then it updates the physics of the bodies based on time ‘dt’ , but if there is inter-penetration then it keeps on dividing dt until the bodies are not inter-penetrating ( ie no collision or collision) . Mathematically, if you divide dt by half enough times, then dt will eventually reach 0. And since the driver assumes that the bodies were not penetrating the initial time (at time dt = 0) it will always find a time when the two bodies are not penetrating. This is working fine. But the following scenario comes up. After the impulse is applied, what if the two bodies are still inter-penetrating, albeit in different coordinates? After the impulse is applied the program exits from the while loop. When the driver re-enters for the next frame, it does it usual stuff and assumes that no inter-penetration is taking place initially. (which is a wrong assumption, as the impulse still results in inter-penetration and currently the two bodies are penetrating). Then the program just goes in infinite loop as it is trying to divide the time in half each time and trying to find a time such that there was no interpenetration. But that time never exits as there is inter-penetration at dt = 0. So what should I do next? If impulse results in other parts of being body not involved in the collision being inter-penetrated, how can I prevent that ? I am completely stuck and any help will be highly appreciated. Thanks so much SM