Collisions

Geoff Canyon gcanyon at gmail.com
Sun Mar 25 12:27:32 EDT 2012


This works only if the balls hit head-on. Otherwise you need to do the
trig. As a simple example, say there are two balls headed toward each
other. Each has a radius of 2^.5. Ball A is moving at -2 units per second
on the x axis, i.e. to the left, and its center has a Y coordinate of 2.
Ball B is moving at 2 units per second on the x axis, i.e. to the right,
and its center has a Y coordinate of 0. When the balls collide, they will
be 2 units apart both horizontally and vertically, hence they collide at a
45 degree angle. Let's say that they're at 0,0 and 2,2 at the time of the
collision. They won't simply exchange velocities. Their original motion on
the x axis is translated entirely into motion along the y axis. After the
collision, ball A will have an X coordinate of 2, and be moving at 2 units
per second on the Y axis, i.e. up. ball B will have an X coordinate of 0,
and be moving at -2 units per second on the Y axis, i.e. down. You need to
calculate the angle between the balls at the moment of collision, and use
the sine and cosine to figure out what happens from there.

All of the above is from my head so feel free to check me.

On Sun, Mar 25, 2012 at 8:56 AM, Jim Hurley <jhurley0305 at sbcglobal.net>wrote:

> P.S.
>
> In the simplest case, equal  masses, just interchange the velocities of
> the two balls after the collision.
>
> Proof:
> If one assumes that the solution is unique, and since interchanging the
> velocities conserves momentum and energy (for balls of equal mass), this
> solution is THE solution.
>
> Jim
>
> > Richard,
> >
> > Collision detection is the easier part. Just calculate the distance
> between centers and, if it is greater than the sum of the radii (assuming
> they are circular) you have a collision.
> >
> > The more difficult part is the physics, what happens after the
> collission. Are they of equal mass and size? You need to conserve momentum
> and energy.
> >
> > To get started you may  look at a pool game. See:
> >
> >     http://jamesphurley.com/runrev.html
> >
> > and look for "Nine ball pool."
> >
> > You may  want to also checkout "Bouncing ball tools" at the same site to
> see how to work with collision with different shapes, and how to deal with
> enclosures that are may  be convex.
> >
> > Jim Hurley
> >
> >
> >
> >
> >> I'm working on a very simple iPad app where 4 large shapes randomly
> float around on the screen.  What I'd like to do is have them be able to
> bounce off each other if they happen to touch.  Are there any tutorial
> pages or sample stacks out there that anyone knows of that I could use as a
> starting point?  I can do collision detection with intersect, but before I
> spend countless hours reinventing the wheel, I thought I'd ask.
> >>
> >> ---
> >> Richard MacLemale
> >> Music =
> >> http://www.richardmac.com
> >>
> >> Programming =
> >> http://www.macandchee.se
> >
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list