for (i = 0; i < this.particles.length; i++) {

p = this.particles[i];

for (j = 0; j < this.surfaces.length; j++) {

s = this.surfaces[j];

if (s.testInequality(p.curr.x, p.curr.y)) {

vel

= p

.curr

.minusNew

(p

.prev);
sDotV = s.normal.dot(vel);

if (sDotV < 0) {

// compute momentum of particle perpendicular to normal

velProjection = vel.minusNew(s.normal.multNew(sDotV));

perpMomentum = velProjection.multNew(this.coeffDrag);

// compute momentum of particle in direction of normal

normMomentum = s.normal.multNew(sDotV * this.coeffRest);

totalMomentum = normMomentum.plusNew(perpMomentum);

// set new velocity w/ total momentum

newVel = vel.minusNew(totalMomentum);

// project out of collision

mirrorPos = s.normal.dot(p.curr.minusNew(s.p1)) * this.coeffRest;

p.curr.minus(s.normal.multNew(mirrorPos));

// apply new velocity

p

.prev = p

.curr

.minusNew

(newVel

);
}

}

}

}