refract method
Implementation
Vector2D refract(Vector2D 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 .vec2(
r*x - (r*dot + d)*n.x,
r*y - (r*dot + d)*n.y,
);
}
return this;
}