• FEATURED

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

## Elastic collision

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1calculemus1988  Members

Posted 30 August 2011 - 02:56 PM

I read this but I need some help.

"
We begin by calculating the velocity of the center of mass for the collision.
This value is determined by adding the velocities of the two colliding objects and then dividing by the total mass of the objects.
If the two colliding objects hit each other, this velocity is the velocity that the resulting composite object would have.
"

Here is an image.

Questions:

1. First of all, I don't understand what is the center of mass for the collision?
2. What is this combined velocity, and having sum of velocities over mass, is that some formula I should know?

This is the code for the collision:

private void BounceAsteroids(Sprite asteroid1, Sprite asteroid2)
{
{
// both objects have mass 1, so we divide with 1 + 1 = 2
Vector2 cOfMass = (asteroid1.Velocity + asteroid2.Velocity) / 2;

Vector2 normal1 = asteroid2.Center - asteroid1.Center;
normal1.Normalize();

Vector2 normal2 = asteroid1.Center - asteroid2.Center;
normal2.Normalize();

asteroid1.Velocity -= cOfMass;
asteroid1.Velocity = Vector2.Reflect(asteroid1.Velocity, normal1);
asteroid1.Velocity += cOfMass;

asteroid2.Velocity -= cOfMass;
asteroid2.Velocity = Vector2.Reflect(asteroid2.Velocity, normal2);
asteroid2.Velocity += cOfMass;
}
}

I understand the code as a programmer, but I don't get the physics here. Why subtract cOfMass, then calculate the reflection vector and then again add cOfMass?

Thanks

### #2japro  Members

Posted 30 August 2011 - 03:14 PM

It's not the center of mass, its the velocity of the center of mass of the system. That velocity has to be conserved on impact, otherwise the collision would not conserve the impulse.

Think about the case where one asteroid doesn't move. In that case the moving asteroid would just be reflected while the other one wouldn't move at all... Even worse, if they collide at an arbitrary angle, they would simply be reflected into the opposite direction of their original movement.

### #3calculemus1988  Members

Posted 30 August 2011 - 03:49 PM

### #4japro  Members

Posted 30 August 2011 - 03:53 PM

Uhm, didn't I just answer that? (Edit: well I kinda did, but it was rather "implicit" ) Subtracting the velocity of the center of mass transforms the system to an inertial system where the center of mass is at rest. Adding it transforms back...

### #5calculemus1988  Members

Posted 30 August 2011 - 04:06 PM

Let's consider just this code and go slowly line by line, without physics terms like "inertial system". Just keep it common sense, I am in CS not in Physics

asteroid1.Velocity -= cOfMass;
asteroid1.Velocity = Vector2.Reflect(asteroid1.Velocity, normal1);
asteroid1.Velocity += cOfMass;


1. Are you saying that line one makes asteroid2(the other one) basically a static object?
2. I know what reflection vector is, I am ok here.
3. I am lost on line 3.

And what is the sum of velocities over mass formula?

Edit: I consider getting some physics books for game programming, I see gamedev.net has some recommendations.

### #6japro  Members

Posted 30 August 2011 - 04:18 PM

asteroid1.Velocity -= cOfMass;
asteroid1.Velocity = Vector2.Reflect(asteroid1.Velocity, normal1);
asteroid1.Velocity += cOfMass;


1. Are you saying that line one makes asteroid2(the other one) basically a static object?

No, it makes the center of mass of the whole system static.

2. I know what reflection vector is, I am ok here.

3. I am lost on line 3.

this just reverses the transformation that was done in line 1.

Its mostly a style question but if I had to write that function it would look like this:
[source lang="cpp"]//change the frame of reference to one where the center of mass is at restasteroid1.Velocity -= cOfMass;asteroid2.Velocity -= cOfMass;//perform elastic collision along normal vector asteroid1.Velocity = Vector2.Reflect(asteroid1.Velocity, normal1);asteroid2.Velocity = Vector2.Reflect(asteroid2.Velocity, normal2);//chage back to the original frame of referenceasteroid1.Velocity += cOfMass;asteroid2.Velocity += cOfMass;[/source]
Kinda makes the whole intent more obvious. Also normal1 = -normal2... only calculating one and changing the sign is on less (expensive) normalization.

### #7calculemus1988  Members

Posted 30 August 2011 - 04:38 PM

Look at this image

The author did a mistake I think. This is what he did:

Vector2 normal1 = asteroid2.Center - asteroid1.Center;
Vector2 normal2 = asteroid1.Center - asteroid2.Center;


And this is what I think it should be:

Vector2 normal2 = asteroid2.Center - asteroid1.Center;
Vector2 normal1 = asteroid1.Center - asteroid2.Center;


Mine agrees with the image and from what I know about reflection angles. The direction of the normal matters. The reflected angle will be in the half-plane where the normal points to, not away from. Agree?

Anyways I am kinda geeky about understanding stuff I do, I will read for details in the books, there are good ones on physics for game programming, and one of them in contents has collision of two circles, similar stuff to this one.

### #8japro  Members

Posted 30 August 2011 - 04:53 PM

I don't think there is a canonical way to define the sign of those normals. It pretty much depends on how the signs in the "Reflect" methods look like. But yes, your version is consistent with the graphics.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.