Sunday, September 14, 2014

Elastic collisions

Hi! Today, I will tell you about a project that I have been working on in Independent study; an Elastic Collision simulator.

The Idea:
An Elastic Collision is one in which momentum and kinetic energy are conserved. Over the summer, I made a charged particle simulator, and starting this school year, I took the idea and made a gravity simulator. The primary problem with these two simulators is that particles can move inside of each other. In order to solve this problem, I want to implement Elastic Collisions, so I am working on the code with a different simulator. After I finish it, I plan to copy the code over to these two simulators to improve them as well.

The process:
To start this process, I first had to learn how Elastic collisions work. I found an equation to model the motion on Wikipedia. In order to implement this algorithm, I had to remember how to use arc tangent to compute angles from x and y speeds. The problem with arc tangent is that it has a range of (-pi/2, pi/2), so I had to figure out what the actual angle is depending on the sign on the X speed. If the X speed was negative, I would need to add pi to my result to get the correct angle. In order to calculate phi, I used the difference between x and y coordinates using the same basic system with arc tangent. In order to calculate the mass of a particle, I would square its radius.

The result:
This worked better than I expected, as a majority of the collisions looked accurate. Despite this, about 30% of my collisions were not working out as I expected them to. I started analyzing my code for bugs, but I could not find any. Eventually a classmate said that I could be having problems with particles tunneling into each other and preforming multiple collisions before escaping. Using this advice, I worked on creating anti-tunneling code.

Anti-tunneling:
In order to stop tunneling, I worked on a system where if two particles move into each-other, one will move backwards at the same angle until it is outside of the other. This seemed to solve my problem; however, I started having problems where particles would teleport when they collided. Thinking that this could be caused by multiple attempt to stop tunneling, I created a cool down timer for collisions, but this caused particles to get trapped inside of each other.

The state of my progress:
I have made significant progress on this project; however, I still have two bugs that I need to fix. I am hoping to fix these problems next week. See you then!

No comments:

Post a Comment