/** * Returns the reflection of a vector u on a surface with normal n. Vector u points towards the * surface, vector r (result) points away from the surface. n is assumed to be normalized. * * @param u vector that will be reflected on the surface * @param n normal of the surface * @return reflected vector, facing away from the surface */ public static Vector3 reflect(Vector3 u, Vector3 n) { double scalar = Vector3.dotProduct(u, n) * -2d; Vector3 result = Vector3.timesScalar(n, scalar); result = Vector3.add(result, u); return result; }