我有一个春天的课。 我想给 Spring 添加阻尼,让它在一段时间后停止,但我应该如何添加它?
我的春季班是:
class Spring:
def __init__(self, p1, p2, lenght, k, damping):
self.particle1 = p1
self.particle2 = p2
self.lenght = lenght
self.k = k
self.damping = damping
def update(self):
force = self.particle2.position.subtract(self.particle1.position)
x = force.getMagnitude() - self.lenght
force = force.normalize()
force.multiplyBy(self.k * x)
self.particle1.applyForce(force)
force.x *= -1
force.y *= -1
self.particle2.applyForce(force)
我还有粒子 1 和粒子 2 的速度和加速度。