[MATH] Bouncing balls

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

User avatar
Jim e
Calc King
Posts: 2457
Joined: Sun 26 Dec, 2004 5:27 am
Location: SXIOPO = Infinite lives for both players
Contact:

Post by Jim e »

King Harold wrote:Why are we pretending they are Perfect Elastic collisions?
Are we forgetting this is a calculator game?

The example I posted doesn't required advanced math...well actually it doesn't need anything but add and subtract. Its not correct though but for a game it could be implemented extremely quickly without killing your self for it.

If you really want to do the absolute correct way, theres this site which pretty much walks you through everything.
http://www.plasmaphysics.org.uk/collision2d.htm

The cpp at the end will give you a nice layout if you just want to port.

Such a collision does not exist..
Really? Someone needs to tell all those electrons and protrons out there to cut it out.
Image
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Really? Someone needs to tell all those electrons and protrons out there to cut it out.
As you well know you cannot apply normal physics to quantum particles. You can try - but it won't make sense.
coelurus
Calc Wizard
Posts: 585
Joined: Sun 19 Dec, 2004 9:02 pm
Location: Sweden
Contact:

Post by coelurus »

First, I've studied a course in nuclear physics, in particular (no pun intended) nuclear reactions. And the elastic collision calculations make a lot of sense. One very easy way to see how linear momentum and energy is conserved is to watch electron and positron pairs being spontaneously created and merged.

Second, _all_ collisions are elastic, it's just that you usually skip a lot of interacting details. Linear momentum can be represented in many weird ways.

Third, I'd rather follow this for code, since it only does it with vector algebra. I prefer vectors to trigs, just feels a whole lot safer (I don't particularly like arctan with fpm!).
http://www.sjsu.edu/faculty/watkins/collision.htm
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

You're just hiding the trig then. You know how dot and cross products are calculated..
An elastic collision is a collision in which the total kinetic energy of the colliding bodies after collision is equal to their total kinetic energy before collision.
I can see that happening to quantum particles, they have nothing directly to do with games or their physics or anything normal (and don't say quantum particles are normal just because there are many of them). I wasn't talking about quantum particles at all, you're taking my arguments way too far as to let it sound ridiculous. Fine tactic but I don't appreciate it.

Now back to normal physics in which a collision is by definition never elastic. You can't really complain about that - do you know anything that will bounce forever? (in a vacuum). When an object hits an other object the kinetic energy will never be the same as before, you can have sound, heat, electromagnetic radiation even (thinking of quantum particles..) and that has to come from somewhere, sacrificing some kinetic energy seems logical but it could come from mass (how does that work with quantum particles?) it both happens but normally the objects you are throwing at eatchother are not instable nuclei or other small things that can break up into .. well we have to ask coelurus what happens when you're messing with quantum particles.
coelurus
Calc Wizard
Posts: 585
Joined: Sun 19 Dec, 2004 9:02 pm
Location: Sweden
Contact:

Post by coelurus »

I know how I calculate dots and crosses, and I don't really hide any trigs. One could use the cos/sin-expressions, but I prefer the comp-wise sum and swizzling. They are two different ways of calculating the products. If you choose one, you don't hide the other.

My bad on the elastic collisions thing, mixed various types of energies a wee bit. But it's not right to say that collisions by definition are never elastic in the real world. That's like saying God exists, we don't know for sure. Then again we don't have a rigid definition of God afaik, so it's hard to say if we've already found "it" (dont touch this!).

And I don't see how I took your argument too far. You said one cannot apply normal physics to quantum particles, but that does work to some extent. Conservation of momentum?

To get a slightly bit more on-topic, even though it hasn't really become off-topic just yet, how's it going for the thread author?
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Post by driesguldolf »

Very interresting but I think Jim e has a point: :P
Jim e wrote:Are we forgetting this is a calculator game?
So nuclear physics and quantum particles are cool but in this context entirely useless. 8)

Okay, heres what i want to do with the 'game':
- The name changed to 'BallSim'
- Before implementing gameplay I'll first try to get a watchable demo
- @Jim e: I looked at your code, (cannot get the allegro dll to work but the source is simple enough), I saw that you simply swap the vectors if balls bounce... Ok this is very simple, but my balls have a radius of 4pixels (8x8pixels circle images) so this wil look very unnatural
- All the balls have the same mass (this should simplify calculations a lot)
- Ignore the 'spin' effect
- (*) I figured out how the transport of energy works, basically if a ball doesn't hit another ball straight only a part of the balls energy is transferred (compare incoming angle with the vector that 'pushes' against the other ball), this means that the images i showed a page earlier are not correct (I had i hunch they weren't)

I'm going to south France (1 July) for 2 whole weeks so I won't be around for a while :(
I'll see if I can explain the last line with pictures tomorrow (probabely not)

Ofcours it is impossible for me to be without my laptop for 2 weeks so I will take it with me, I inted to finish the BallSim theory and implement it and I will start working on a fast 8x8 tilemapper
coelurus
Calc Wizard
Posts: 585
Joined: Sun 19 Dec, 2004 9:02 pm
Location: Sweden
Contact:

Post by coelurus »

What about fabricating various important cases of bounces? A sort of extension of Jim's 4-way cases into 8 cases or whatever.
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Post by driesguldolf »

@Coelurus: No need! I have entirely solved all problems with the bouncing! :mrgreen: , now just implement it...
It turns out there isn't such a thing as an imaginary wall (it IS imaginary :P)
I will explain my theory, but that post will take some preparation.

Now I think of it... Jim e was right the whole time! It IS a transfer of energy but if the balls hit sideways only a part of that energy is transferred
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Post by driesguldolf »

Okay, I promised that I would explain, so here goes:
The text in blue are the calculations for this example, in black the explanations in a general case

Image
Let's take a simple example
In blue is the original movement of the ball.
In this example:
Ball#1: angle=0°, size=5
Ball#2: angle=90°, size=5
Impact angle=45°


Image
What happens?
On contact there is a force from ball#1 on ball#2.
Now because of different angles only a part of the energy is transferred, I believe it's some scalar product of the blue and the grey vectors.
The magnitude of the impact is the size of the green vector, this is r*cos(α-β) where α is the angle of impact, β is the incoming angle of Ball#1 and r the 'speed' of Ball#1.
This is the effective amount of 'energy' that will be transferred.
Okay the impact vector has a size of 5*cos(45°-0°)=±3.54 (5*√(2)/2)
and an angle of atan((y2-y1)/(x2-x1)), here 45°.


Image
Now we have two vectors, simply add them. The red vector is the new vector of Ball#2.
It is definately easy when you represent vectors with deltax and deltay, then you just have to add them.
But how do you add 2 vectors when all you have are 2 angles and 2 sizes?

Image
But what happens with ball#1?
There comes Newton!
His third law of motion says:
Newton wrote:"to every action force there is an equal, but opposite, reaction force".
Image
Simply add it with the original vector

Image
The final result, compare it with the first image, if you don't believe me, take 2 tennisballs and roll them against each other

This also applies when 2 balls roll into each other, then you just have to do this calculation 2 times, one for Ball#1 rolling into Ball#2 and another time for Ball#2 rolling into Ball#1

Only one thing remains... How do you add 2 vectors when all you have are 2 angles and 2 sizes?
EDIT: Ok, it is very difficult with polar coords, on to the deltax-deltay method...
Post Reply