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.
↧