reflect method

V2 reflect(
  1. V2 normal
)

Reflects this vector off a surface with the given normal.

normal is assumed to be normalized.

Implementation

V2 reflect(V2 normal) {
  double dot = dotProduct(normal);
  return _v2(
    x - (2.0*normal.x)*dot,
    y - (2.0*normal.y)*dot,
  );
}