http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: balls



Hallo,

here's a perfect example of "applying what you once learned in a maths
lesson". It's just a simple case of Conservation of Momentum and Newtons
Experimental Law. It's a bit difficult to explain without diagrams but here
goes (explained with 1D).

When the balls bounce around they'll either hit each other, or hit a solid
wall I assume. Before a ball goes into collision it will have velocity "u1".
When it leaves the collision it can have a different velocity "v1". If it is
colliding with another ball then the same can be said for this one, the
velocity going into the collision (u2) can be different from the velocity
going out of the collision (v2). The important thing to note is that
momentum is conserved throughout this collision, a simple transference
occurs. Momentum is calculated like...

    momentum = velocity * mass

And Conservation of Momentum states that the total momentum involved before
the collision is exactly the same as that total momentum after the
collision...

    m1 * u1 - m2 * u2 = m1 * v1 + m2 * v2

The reason I'm doing a subtract here is because both balls are travelling
towards each other, hence in different directions. m1 and m2 are the masses
of your two balls. You should know the velocity going into the collision and
you know the masses so immediately a big chunk of the equation becomes easy
to calculate. What you need now is the velocities of the balls coming out of
the collision (v1 and v2) but this is impossible with the current equation
since there are two unknowns. You now have to resort to something called
Newtons Experimental Law which is simply...

    v1 - v2 = -e(u1 - u2)

The constant "e" in this equation is called the Co-efficient of Restitution.
Basically, the bigger this value, the more bouncy your collision will be.
This value can vary like 0 < e < 1. (I don't believe in e=1 :0). e is a
value which you can make up yourself and modify but it is a constant that
varies depending on the types of both balls, not just one of them.

So you know u1, u2 and e, what you have here is a simple simultaneous
equation! (remember THEM from maths? :0)

Let's say I had the following values...

    e = 0.2
    u1 = 2
    u2 = -3            (moving the other way)
    m1 = 1
    m2 = 2

I would now go onto calculate the collision as follows...

    Conservation of Momentum:
    1 * 2 - 2 * 3 = v1 + 2 * v2
    2 - 6 = v1 + 2 * v2
    -4 = v1 + 2 * v2

    NEL:
    v1 - v2 = -0.2(2 + 3)
    v1 - v2 = -0.2(5)
    v1 - v2 = -1

    Simultaneous equations are:
    v1 + 2(v2) = -4
    v1 - v2 = -1

    (multiply second equation by 2)

    2(v1) - 2(v2) = -2

    (add the two equations together to get rid of v2)

    3(v1) = -6
    v1 = -2

    (substitute v1 into any equation to calculate v2 - 1st for example)

    -2 + 2(v2) = -4
    2(v2) = -2
    v2 = -1

This is great, whenever I write examples like this the numbers I choose
always provide nice answers - weird :0)

But that's the gist of it. If you want to extend the idea into 2D or 3D
space then it's really simple, just remember that you MUST resolve your
velocities along the x, y and z axes.

I noticed that you have a UK mail account so maybe you're from the UK :0).
If so then try and take Maths and Further Maths for A-Levels. If you do so
then making calculations like this will become second nature and will become
a lot more fun. Hell, you'll even be able to apply collisions to these
babies when they're spinning, ain't that cool :0)

Seeya,
- Don

-----Original Message-----
From: Eudoxus3 <Eudoxus@freeuk.com>
To: Game programmer <gameprogrammer@gameprogrammer.com>
Date: 03 September 1999 09:37
Subject: balls


>Hi,
>
>Does anyone have any routines for calc'ing many bouncing ball's movements.
>
>
>Regards,
>
>Matt. W.
>--
>***  eudoxus@freeuk.com  ***  http://members.xoom.com/eudoxusM/
>                 mwebster@apsoft.co.uk
>
>=================================================================
>To SUBSCRIBE or UNSUBSCRIBE please visit
>http://gameprogrammer.com/mailinglist.html
>
>


=================================================================
To SUBSCRIBE or UNSUBSCRIBE please visit
http://gameprogrammer.com/mailinglist.html