Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- collDistance = (self.DIAMETER + particle.DIAMETER) / 2
- dx = particle.position.x - self.position.x
- dy = particle.position.y - self.position.y
- e = self.ELASTICITY * particle.ELASTICITY
- r = self.DIAMETER / 2
- distance = math.hypot(dx, dy)
- if distance < collDistance:
- #if particle in self.collision:
- # return True
- #self.collision.add(particle)
- vp1 = self.velocity.x * dx / distance + self.velocity.y * dy / distance
- vp2 = particle.velocity.x * dx / distance + particle.velocity.y * dy / distance
- dt = (self.DIAMETER - distance)/(vp1 - vp2)
- self.position.x -= self.velocity.x * dt
- self.position.y -= self.velocity.y * dt
- particle.position.x -= particle.velocity.x * dt
- particle.position.y -= particle.velocity.y * dt
- dx = particle.position.x - self.position.x
- dy = particle.position.y - self.position.y
- distance = math.sqrt(dx * dx + dy * dy)
- ax = dx / distance
- ay = dy / distance
- va1 = (self.velocity.x * ax + self.velocity.y * ay)
- vb1 = (-self.velocity.x * ay + self.velocity.y * ax)
- va2 = (particle.velocity.x * ax + particle.velocity.y * ay)
- vb2 = (-particle.velocity.x * ay + particle.velocity.y * ax)
- vaP1 = va1 + (1 + self.ELASTICITY) * (va2 - va1) / (1 + self.mass / particle.mass)
- vaP2 = va2 + (1 + self.ELASTICITY) * (va1 - va2) / (1 + particle.mass / self.mass)
- self.velocity.x = vaP1 * ax - vb1 * ay
- self.velocity.y = vaP1 * ay + vb1 * ax
- particle.velocity.x = vaP2 * ax - vb2 * ay
- particle.velocity.y = vaP2 * ay + vb2 * ax
- self.position.x += self.velocity.x * dt
- self.position.y += self.velocity.y * dt
- particle.position.x += particle.velocity.x * dt
- particle.position.y += particle.velocity.y * dt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement