Homework 2
Problem A
For my simulation I choose to enclose sphere-like objects within a 10 x 10 x 10 cube. To do this I wrote the framework of a rigid body simulator as outlined in the Baraff course notes, however, I did not implement force or torque handling. Since there are no forces or torques in the system (and therefore no acceleration), I used a simple Euler integrator, although I implemented a mid-point integrator as a proof of concept. My sphere-like objects were generated using a parameterization of a sphere where each vertex on the surface of the sphere was pushed outwards a random amount between 0 and 10% of the radius of the sphere. This gave the spheres as slightly jagged look and made the angular velocity visible.
For collision detection, I used the PQP library. To detect collisions, I created a PQP_Model of each object in the scene and the six cube walls and then called PQP_Collide with each object against the six walls of the cube and each other object in the scene. When an object collides with one of the six walls of the cube, the velocity of the object is projected onto the surface normal of the face of the cube in collision. Twice that result is then added back into the velocity of the object. This effectively reverses the direction of the velocity perpendicular to the cube wall. When an object comes into contact with another object, the same process is used; however, the velocities are projected onto the vector connecting the centers of the two objects. This approximates (since the objects are not perfect spheres) reversing the component of the velocity perpendicular to the point of contact.
Problem B
I analyzed the performance of my algorithm when the number of object, the number of polygons and the size of the objects were varied. For all of these tests I removed the OpenGL display code from the simulation and timed the simulator ten times doing 1,000 time steps each time, averaging the ten trials. The results are presented below:
|
|
For this simulation I varied the number of objects in the scene from five to fifty while holding the number of triangles fixed at 422. The radius of the object was selected randomly from between 0.25 and 2.0. Since the number of pair wise interactions for a set of n bodies is n2, we would expect the simulation time to grow as n2. I have plotted the best fit quadratic line (0.003n2 + 0.007n + 0.31) as found by Microsoft Excel on the graph along with the data points.
|
|
For this simulation I varied the number of triangles that made up each object from 6 to 762. The number of objects was fixed at thirty and the radii were again randomly selected between 0.25 and 2.0. As I said before, the number of pair wise interactions for a set of n bodies is n2, and since we are varying the number of triangles for each of the n bodies, if the collision detection algorithm were naively testing each polygon against each other polygon, we would expect the simulation time to increase quadratically with the number of triangles. PQP, however, uses a BVH, so it is not testing each polygon against each other polygon. For this reason, we expect the simulation time to increase with the number of triangles (since the BVH will be deeper and/or the number of pair wise tests will increase), however, it is not clear exactly how the time grows with an increase in the number of triangles.
|
|
For this simulation I varied the radius of the objects in the scene from 0.1 < r < 1.1 to 1 < r < 2. The plot shows the simulation time against the mean of the range of radii. The number of objects was fixed at thirty and the number of triangles at 422. As the radii of the objects is increased, we expect the number of collisions to increase which increases the average depth PQP needs to descend down the BVH for a test and the number of actual polygon to polygon test that are required.
Problem C
I implemented a simplified version of the sweep and prune algorithm to reduce the number of pair wise collision tests performed using PQP. Since all the objects are sphere-like, I was able to bound them using a cube and since they are the same size, I was able to use the same cube for all the objects. This means that I only kept track of one edge for each object. To judge overlap I simply found the distance between two adjacent edges and checked if it was less than the side length of the bounding cube. Like in normal sweep and prune, I only did a pair wise collision test if there was overlap in the x, y and z directions. Some performance results from implementing the modified version of sweep and prune are presented below. For all of these results, the number of triangles was fixed at 422, the radius was fixed at 1 and the number of objects was varied.
|
|
This simulation shows the simulation time of the brute force method that was used for part A and the new sweep and prune method that I implemented for part C. As can be seen by the trend lines, the original brute force method grows n2 whereas the new sweep and prune method is linear. The constants for the sweep and prune method are also superior to the brute force method.
|
|
This is the same simulation as the above chart except this time I have plotted the number of pair wise tests that were actually performed using PQP against the number of tests that would have been performed by the brute force method used in part A. As can be seen, the number of tests grows as n2 for the brute force method whereas for the sweep and prune method the number of tests actually decrease. I believe the decrease is an artifact of the small sample size. One would still expect the number of pair wise tests performed using PQP to increase slightly as the number of objects grows, however, nowhere near as quickly as the possible number of tests.
The program can be downloaded here.
The source can be downloaded here.