# Circle-Circle impulse resolution not working properly

This topic is 374 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am doing a little physics project with circle circle collisions for now, and have tried to do impulse resolution for collisions with 2 circles, using the following code.

relativeVelocity = (other.doVerletVelocity()).subtract(self.doVerletVelocity())
normDirecVel = relativeVelocity.dotProduct(collisionNormal)

restitution = -1 - min(self.restitution, other.restitution)

numerator = normDirecVel * restitution

impulseScalar = numerator / float(1 / self.mass) + float(1 / other.mass)

selfVel = self.doVerletVelocity()
otherVel = other.doVerletVelocity()

impulse = collisionNormal.scalarMult(impulseScalar)

selfDV = impulse.scalarMult(1 / self.mass)
otherDV = impulse.scalarMult(1 / other.mass)

newSelfVel = selfVel.subtract(selfDV)

self.oldPos = (self.center).subtract(newSelfVel.scalarMult(dt))
other.oldPos = (other.center).subtract(newOtherVel.scalarMult(dt))

The problem seems to be that whatever value I give to self.mass and other.mass, the output stays exactly the same, the values that I used are:

center = Vector(0, 0)
oldPos = Vector(0, 0)
accel = Vector(0, 0)
mass = 100
restitution = 0.001

center2 = Vector(0, 3.20)
oldPos2 = Vector(0, 3.201)
accel2 = Vector(0, -1)
mass2 = 1
restitution2 = 1

the output was:

0.0      0.0      0.0      2.165000000000114
0.0      0.0      0.0      2.1360000000001174
0.0      0.0      0.0      2.1066000000001206
0.0      0.0      0.0      2.076800000000124
0.0      0.0      0.0      2.046600000000127
0.0      0.0      0.0      2.0160000000001306
0.0      0.0      0.0      1.985000000000134
CIRCLE INTERSECTION
0.0      -1.985000000000134      0.0      3.938600000000271
0.0      -3.970000000000268      0.0      5.891800000000408
0.0      -5.9550000000004015      0.0      7.844600000000544
0.0      -7.940000000000535      0.0      9.797000000000681

I changed the values for the masses to make them higher, bu the output still remained the same, if you could get to the bottom of this, it would be much appreciated.

##### Share on other sites

I noticed this:

impulseScalar = numerator / float(1 / self.mass) + float(1 / other.mass)

You are missing parentheses:

impulseScalar = numerator / ( float(1 / self.mass) + float(1 / other.mass) )

##### Share on other sites

Dirk Gregorius, That does not have an effect on the values outputted by the method.

##### Share on other sites
23 hours ago, Dirk Gregorius said:

I noticed this:

impulseScalar = numerator / float(1 / self.mass) + float(1 / other.mass)

You are missing parentheses:

impulseScalar = numerator / ( float(1 / self.mass) + float(1 / other.mass) )

I tried that, yet it has no effect on the values. When displaying the circles on the screen, using pygame module, it showed that after colliding, the circles moved in opposite directions, but with velocities faster than what they collided with.

Edited by Bob Dylan

##### Share on other sites

Doesn't that appear strange to you? Obviously it should have an effect since :

n/a + b != n / (a + b) for any b != 0

##### Share on other sites
1 minute ago, Dirk Gregorius said:

Doesn't that appear strange to you? Obviously it should have an effect since :

n/a + b != n / (a + b) for any b != 0

It definitely is strange, yet what I described is the case. I think the error might be in the way that 1/mass is calculated because changing the mass when defining the particle object has not bearing on the resultant impulse.

##### Share on other sites

What language are you programming in? It might be that it is the type promotion. Try

float(1.0f / self.mass)

Either way, this should be easy to find. Simply debug and step through the code.

##### Share on other sites
17 minutes ago, Dirk Gregorius said:

What language are you programming in? It might be that it is the type promotion. Try

float(1.0f / self.mass)

Either way, this should be easy to find. Simply debug and step through the code.

Are you supposed to deal with penetration in the collision detection phase, or the impulse resolution phase? I ask this because that might be what is throwing this off, because as soon as they collide, the circles make a large jump, which might be affecting their velocities as i am just approximating velocity as current position - old position divided by the timestep, since my velocity verlet implementation does not deal with veloicty explicitly.

Edited by Bob Dylan

##### Share on other sites

You detect penetration in the collision phase. You can deal with it in the impulse phase or in a separate penetration recovery phase.

##### Share on other sites
Just now, Dirk Gregorius said:

You detect penetration in the collision phase. You can deal with it in the impulse phase or in a separate penetration recovery phase.

Thanks, I think that is what is causing the value of the velocities to be large after impulse resolution.

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 12
• 18
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633359
• Total Posts
3011513
• ### Who's Online (See full list)

There are no registered users currently online

×