function intersect_sphere(origin, dir, center, radius)
{
const a = lensq(dir);
const b = dot(dir, sub(origin, center));
const c = lensq(sub(origin, center)) - radius * radius;
if(b*b - a*c < 0)
return [];
let t0 = (-b - Math.sqrt(b*b - a*c)) / a;
let t1 = (-b + Math.sqrt(b*b - a*c)) / a;
if(t1 < 0)
return [];
else if(t0 < 0)
return [t1];
else if(t1 != t0)
return [t0, t1];
else
return [t0];
}