1. Member
Join Date
Sep 2009
Posts
41
Rep Power
0

## Inelastic circle collisions

Hey I'm creating a gravity-physics type simulator that consists of circles that gravitate toward each other. It works pretty good so far except for the collisions. I want the collisions to be inelastic so the circles bunch up nicely. Right now, 2 circles will work alright, they will bunch up and act as one. But what happens with more than 2 is the circles pull each other through other circles. Then the jumbled blob will accelerate in a random direction because the gravity of one pulls on the other, but they move as a unit. The collision detection im using is a simple distance of centers vs sum of radii. I need some way to keep the circles from intersecting, but still be effected by the gravity. Im thinking that they can be held together by the gravity force, but I dont know any good method to keep them repelled. any suggestions on how to approach this?
thanks.

2. Show us the problem code or error message please

3. Member
Join Date
Aug 2010
Posts
25
Rep Power
0
What are you using to measure the rate of gravitation (movement) of the circles?

4. Member
Join Date
Sep 2009
Posts
41
Rep Power
0
gafa, theres no error message, It just doesn't work.
as for the rate of gravitation, i use the standard force of gravity
I use acceleration = (mass of other object) / (distance between them)^2
then multiply it by a constant. to get a nice real looking rate.

each ball is on its own thread that checks its own acceleration towards other objects, and checks if its intersecting other circles.

5. Without samples of your code that are relevant to the actual program, we cannot help. That formula looks like it would work, but it's hard to tell exactly how exactly it affects the program in general without seeing the big picture.

At the very least, an actual video of the outcome would be helpful.

6. Senior Member
Join Date
Jul 2008
Posts
125
Rep Power
0

## Geometry and physics that can get complex

I think your goal is much more complex
than you may be aware.

I think you want the circles to clump together
without overlapping. You want some way to
halt their movement once the circles touch.

Or something like that.

Keep in mind the following suggestion
is only a part of many formulas that
may simulate some of the laws of physics.

My idea is that you lock a circle into
position in a cluster once it contacts
the boundary of TWO other circles.

Make this condition the one that halts
that circle's movement and causes a
recalculation of the cluster's momentum
(if you are using momentum in your
project).

This works because the contact of the
three circles together creates a triangle
with the centers of each of the circles,
which is rigid, and the circles don't
overlap.

Your algorithm will be watching for,
or even promoting the production of
these triangles.

Possibly, through random motion, the
anticipated positions of the circles
will never occur.

To force this event to happen in a
timely manner, you can make a circle,
upon collision, divide into two minor
circles, then have that pair lock
together with the circle it impacted
with.

7. Member
Join Date
Sep 2009
Posts
41
Rep Power
0
Interesting, I think i will try locking them like you mentioned. as of now, they dont intersect eachother, because they are instantly moved to the outside of the circle, but now they jitter and still accelerate in a random direction. I do have momentum and it works good when bunches hit other bunches, its just the fact that the bunches are accelerating in random directions. If I "lock" them into the bunch i could treat it as a whole.
ill try doing that. ill do a little video of what it looks like, I think its pretty neat so far!

8. Member
Join Date
Sep 2009
Posts
41
Rep Power
0
K i created a little screen cap of my program. You can really see the problem with the very first thing I do, then also again at 1:44. When I zoom out they are still moving, but its so far away so it doesnt really make a difference.

I dont know how much posting code will help, but the actual collision check and gravitation dont take much more than a 10 lines of code each. The way I got the circles to be rigid is it detects the angle of their centers and displaces it so they are right outside eachothers edges. Any suggestions would be awesome, im stumped at this point. I guess I could have posted this in advanced? :/
Let me know if you have any questions too.

9. Senior Member
Join Date
Feb 2010
Location
Waterford, Ireland
Posts
748
Rep Power
7
Your big circle from what i can gather from the video has no magnetic field, atleast it seems to work that way. if you are sending other small circles towards it you must calculate that circles acceleration towards the big circle and how if at all the big circle can attract it until it settles into a uniform orbit.

10. Senior Member
Join Date
Jul 2008
Posts
125
Rep Power
0

## Nice video

The video looks pretty neat.
The problem moves by too quickly
to notice enough of it for me to
form an opinion of what causes it.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•