Jump to content
  • Advertisement
Bob Dylan

Circle-Circle impulse resolution not working properly

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)
newOtherVel = otherVel.add(otherDV)

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)
radius = 1
oldPos = Vector(0, 0)
accel = Vector(0, 0)
mass = 100
restitution = 0.001

center2 = Vector(0, 3.20)
radius2 = 1
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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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
I needed to add more information.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!