@Asdrubal
Thank you for tips. Now it works - we need first scale the direction then add it to the origin. So I replaced
origin.add(direction).scale(distance);
with
let scaledDir = direction.normalize().scale(distance);
sphere.position = origin.add(scaledDir)
Here is the working playground