2D Rigid Body Simulation
For one of my classes, I was tasked with creating some kind of interesting graphics program. I decided to create a 2D rigid body simulation with rotation. The enabling of rotation is what made this project difficult. This stems from the fact that enabling rotation makes detecting collisions significantly more complicated. Without rotation, there are more assumptions that one can make about how different physics objects could be interacting with one another.
This necessitates the use of a more complicated (and more expensive) means of detecting collisions. Here I decided to use the Seperating Axis Theorem. This is a reliable means of detecting collisions between any convex polygons and spheres. The theorem states that if any line can be drawn in between the two shapes, then the shapes are not colliding. There are more details in the video below, but it is applied here by projecting all of the points onto all of the normals and comparing these projections for overlaps. If there is any normal that does not have an overlap, then the two objects can not be colliding.
This project was done entirely from scratch in an extension of Java called Processing. Processing only handles the graphics; everything else is handled by my code.
This project was a lot of fun and I learned a lot. Though I like to think it looks pretty good, there is definitely still room for polish and expansion. Currently, there are some bizarre behaviours that can cause excess rotation. I have a few guesses as to the source of these. For expansion, I would love to try and take this physics model into the third dimension. The detection algorithm could easily be modified for this, it would just require more maths.