Monday 10 March 2014

Physics Simulation

Rigid Body Dynamics


Rigid Body Dynamics deals with the linear and angular motion of non-deformable objects in 3D space. Detecting a collision when two or more rigid bodies come in contact and the way they respond to the collision are crucial to simulate a realistic motion.
A very basic rigid body simulation is implemented in this project. Though, a very simple collision detection method is used, the impulse method used to resolve collisions is quite powerful as it handles response to collisions quite effectively. But, there are several areas in this project where improvement can be made to achieve better results. Though lot of work is to be done to improve this project, it was a really good experience working on rigid body simulation and helped gain an understanding to the way physics works.



COLLISION DETECTION


Collision detection is an important aspect in physical simulation. Rigid objects freely moving and rotating in our rigid world, will have to collide with each other at some point in time. There are several collision detection algorithms used for accurately calculating the collision between different objects. The complexity of the algorithm depends upon the shape of the rigid bodies.
For computational efficiency, bounding volumes are most commonly used to detect collisions. The whole object or mesh is enclosed within a closed volume. A simple shape like sphere or cube is chosen to enclose complex objects to improve efficiency of geometric operations. In collision detection, when two bounding volumes do not intersect, then it is concluded that the objects do not intersect as well.
For our simulation, since we are dealing with simple objects and to keep the collision detection simple, we are enclosing all our rigid bodies within a sphere.

Bounding Sphere


Bounding sphere is one in which the objects are enclosed within a sphere. It is represented by a centre and a radius. Collision detection between bounding spheres is very quick and easy to implement. Hence, this method is chosen for our simulation due to time constraint.
A collision is detected if two bounding spheres intersect each other. The intersection is detected if the distance between their centres does not exceed the sum of their radii.

The flip side in using bounding spheres is that it has more wasted space than a bounding box. Using them can give less accurate results during collision. The two objects detects collision when the bounding spheres touch each other, but when in reality the objects actually doesn’t touch each other.

During collision, contact information is calculated and stored in ContactData class (Figure 4). The data calculated consists of :
Contact normal    –  the normal direction along which the colliding objects has to move after resolution.
Penetration depth – the distance along contact normal, to move the objects so that they don’t intersect each                                 other.
Contact point        – the point where the objects intersects.

COLLISION RESOLUTION


Once a collision is detected and contact data calculated, the collision has to be resolved to obtain appropriate simulation. According to Millington, when two objects encounter a collision, their direction of movement after collision can be obtained from their movement before collision. He terms this as Collision Resolution.
When a collision occurs between two rigid bodies, a collision impulse is calculated. This impulse prevents interpenetration by changing the velocity of the colliding objects instantly. Impulse can be thought if as a huge force integrated over a really short period of time. As force changes the velocity over time, impulse changes the velocity instantaneously. Impulse can be calculated and applied at the point and instant of collision. Since rigid bodies have rotation to them after colliding angular velocity too has to be calculated along with linear velocity.

To calculate the impulse magnitude and direction we use the collision model called as “Newton’s Law of Restitution for Instantaneous Collisions with No Friction.”. This model assumes that the collision process takes no or very small amount of time. At this time, non-collision forces like gravity are not taken into account though they exist before and after collision.
Newton’s Law of Restitution introduces another new quantity, the coefficient of restitution(e). The speed at which the objects separate after collision is controlled by this parameter. Its usually between 0 to 1, differs according to different materials involved in collision. A material with high bouncing effect like ball will have high coefficient of restitution, whereas clay or snowball will be almost zero.
This collision model assumes there is no friction, hence there is no tangential impulse and collision is entirely in the normal direction.

Few problems occurred when the above collision resolution equations were implemented. The main problem was interpenetration between colliding objects. It was quite complex to find the exact time at which two objects touch each other without penetration. Hence, to solve this easily a small amount of penetration is added to impulse to push the objects apart. This handled the resting contact as well, that is when objects come to rest.
Another complication is multiple contacts. To resolve this, separate Contact data is stored for every colliding object, thus handling it.


No comments:

Post a Comment