I enjoy math and physics, so most of my programs revolve around the subjects. I’ve always been pretty fascinated by physics simulators that handle fluid particles (like water, air, etc), so I wanted to try making something similar to one. This program deals only with solid particles that bounce off of one another when they hit. However, the particles are not programmed to bounce off with different force and speed at the proper angle quite yet. I mainly created this to see how I could program collision detection between a large amount of objects. Everything for this is written in Java; I already have a few other big projects going on in C++ and other languages, and GUI is worlds easier to do in Java.
The program uses Java Swing to make a window, and sets up a thread to control the program. To make the particles I use a rectangle array, which lets me control each individual x and y point, as well as the width and height. I also create an array equal to the particle one, which sets a specific x and y speed for each particle (dx dy). By doing all this I have complete control over each particle that I make, no matter how many there are. Now the problem was how to check each one for collisions. First I set up a for loop to check collisions with the window boundary so they all stay on screen. The code for this is important because it keeps the particles within the window bounds at all times, specific to the side of the window. If it is not set up correctly, some of the particles will escape the window, especially when they start colliding. I will explain the code a little later, but at the moment I have to get back to some work. The code is available here for you to look through. I know that some of it is untidy, but I wrote it all in my free time today. Post any questions you have, and I’ll try to answer them when I finish the post.
Tudor Marcu




[...] from: Multiple Particle Collision Detection Aviation [...]
Dear Mr.Tudor Marcu
I am Nguyen Hong Duong. I am from Vietnam.
Now I have to simulate particle collision ( like as Hourglass) . I want to simulate this model in 3D ( with can change velocity rotate, time,Amount particle)
It would be grateful if you show me do that.
I am really sorry because my English skill is not good.
Thank a lot for your help!
my email :nguyenhongduong.hut@gmail.com
Best regards,
Nguyen Hong Duong
Awesome post!