assert normal != null : "Physics.calculateImpulse: normal must be a valid PVector";
assert !(normal.x == 0 && normal.y == 0) : "Physics.calculateImpulse: normal must be nonzero";
PVector numerator = PVector.sub(v2, v1); // calculate relative velocity
numerator.mult(-1 - elasticity); // factor by elasticity
float result = numerator.dot(normal); // find normal component
result /= normal.dot(normal); // normalize
result /= (1 / m1 + 1 / m2); // factor in mass
return PVector.mult(normal, result);
}