void SchQ_Particle_System :: apply_hooks_law(Spring &s){ Vec2D<double> pos0 = s.a->get_position(), pos1 = s.b->get_position(), vel0 = s.a->get_velocity(), vel1 = s.b->get_velocity(); double dx = pos0.x-pos1.x, dy = pos0.y-pos1.y, dvdx = vel0.x-vel1.x, dvdy = vel0.y-vel1.y, dist = pos0.distance(pos1), rdist = dist != 0 ? 1.0/dist : 0; Vec2D<double> force (-(s.stiffness*(dist-s.rest_length) + s.dampening*(dvdx) * dx*rdist) * dx*rdist , -(s.stiffness*(dist-s.rest_length) + s.dampening*(dvdy) * dy*rdist) * dy*rdist); s.a->add_force(force); s.b->add_force(force.multiply(-1)); }