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:

Simulation time as a function of the number of objects
Number of
Spheres
Simulation
Time (s)
5 0.0766856
10 0.627718
15 1.50495
20 1.37641
25 1.90979
30 2.99526
35 3.94162
40 4.82598
45 7.10074
50 7.9141

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.

Simulation time as a function of the number of triangles
Number of
Triangles
Simulation
Time
6 0.627
26 1.068
62 1.53
114 1.938
182 1.989
266 2.847
366 3.312
482 3.774
614 3.816
762 5.602

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.

Simulation time as a function of radius
Minimum
Radius
Maximum
Radius
Mean
Radius
Simulation
Time
0.1 1.1 0.6 1.33831
0.2 1.2 0.7 1.622
0.3 1.3 0.8 2.19068
0.4 1.4 0.9 3.07187
0.5 1.5 1 3.60396
0.6 1.6 1.1 4.17373
0.7 1.7 1.2 4.97289
0.8 1.8 1.3 8.00169
0.9 1.9 1.4 7.4982
1 2 1.5 9.38195

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.

Simulation time using sweep and prune
Number of
Spheres
Simulation
Time
5 0.158135
10 0.356569
15 0.347481
20 0.488154
25 0.584324
30 0.483808
35 0.634523
40 0.679596
45 0.682079
50 0.747711

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.

Number of pairwise tests compared with the maximum possible number
Number of
Spheres
Possible
Tests
Pariwise
Tests
5 10000 106.2
10 45000 173
15 105000 137.2
20 190000 154.3
25 300000 130.9
30 435000 88.4
35 595000 103.3
40 780000 97.2
45 990000 74.9
50 1225000 80.8

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.