The easiest way to go about this is to treat them as perfect circles and to use physics. Collision detection and the physics are two interesting subproblems which I'll expand on below.
Physics
You may believe that the equations governing the collisions of circles are simple. Your presumptions are correct but that doesn't mean the solution is intuitive.
I recall asking one of my classmates (who is a genius) about this in my high school physics class. After his inadequate and too concise explanation (probably because of how simple he believed the question to be) I decided it's easy to work out
What I was lacking in high school was the right approach (no duh...). I had a tough time wrapping my head around this: the force one circle exerts on the other depends on the relative location of the other circle when colliding (e.g. a straight-on or glancing collision). To work-around this complication I decided to orient one the axes of my reference frame to be parallel to the line connecting the two circle's centers. I also made a fundamental simplification – treat the circles as point masses. After that all that's needed is some vector algebra (dot products, norms, and vector projections) to compute the resultant forces from a collision.
"You and I collide"
Checking when two objects are in contact is a problem that's been discussed a lot and there are a lot of efficient ways to do this. Since I was unaware of this I decided to reinvent the wheel. My approach was to simply test each circle against every other circle (i.e. by brute-force). This can be done pretty easily with two nested for loops.
No comments:
Post a Comment