refract method
Implementation
Vector3D refract(Vector3D n, double r) {
final dot = dotProduct(n);
double d = 1.0 - r*r*(1.0 - dot*dot);
if (d >= 0.0) {
d = math.sqrt(d);
return .vec3(
r*x - (r*dot + d)*n.x,
r*y - (r*dot + d)*n.y,
r*z - (r*dot + d)*n.z,
);
}
return this;
}