PDA

View Full Version : 2 spheres with mass collide



User137
27-01-2011, 05:18 PM
Just had a funny idea today to start making a small demo with lots of different mass and size circles. Just moving and bounding from eachother. It just turned out to be little difficult to think of... Went to MsPaint and sketched eventually this:
http://i52.tinypic.com/s30zyf.png

I read about physics loop that can be set running loops as much as frame time milliseconds allow, and that should fix problem that comes with balls colliding to walls and eachother, making chainreactions. For example 60 fps gives
1000ms/60-RenderingTime time for physics, preferrably reduce that a little more for more fluent application.

I hope i didn't make a mistake somewhere, and if not, it may be helpful to someone someday. So as far as the collision part is just in theory level, i'll try and finish that demo in any unknown hour/day in the future 8)

edit: Attachment reduced the image blurry, had to use Tinypic...

I guess i could try make a small summary too (sphere1 is the small, sphere2 is bigger on right):
Final movement vector for sphere1 = Normalize(Sphere1.Pos-Sphere2.Pos)*MoveSpeed2*MassMult2 + movement1*MassMult1 + ReflectVector1*MoveSpeed1*MassMult2

And cool thing about vectors is that they work exactly same way 2D and 3D with hardly any modifications.

Edit2: Sample source and executable of demo included, it works even with gravity! ;D

No.. the bigger the mass of sphere the more it tends to slow down in my tests. With no gravitation and slowdowns, the application comes to almost standstill mode in some time. Also the small spheres seem to push big ones a bit, which could be caused of non-perfect collision detection and their movement. This reflection formula still holds as far as i can see. Although i haven't calculated if the total force remains same after collision, it is basic thing in physics.

arthurprs
29-01-2011, 01:10 AM
I wrote a very similar code a long time ago. Uses form canvas, no external dependencies.

Attached.