code: def ray_spheres_intersection(origin, direction, centers, radii):
      
      b_v = 2.0 * ((origin - centers) * direction).sum(axis=1)
      c_v = ((origin - centers)**2).sum(axis=1) - radii ** 2
      det_v = b_v * b_v - 4.0 * c_v
  
      inters_mask = det_v >= 0
      intersections = (inters_mask).nonzero()[0]
      distances = (-b_v[inters_mask] - np.sqrt(det_v[inters_mask])) / 2.0
  
      # We need only the thing in front of us, that corresponts to
      # positive distances.
      dist_mask = distances > 0.0
  
      # We correct this aspect to get an absolute distance
      distances = distances[dist_mask]
      intersections = intersections[dist_mask].tolist()
  
      if intersections:
          distances, intersections = zip(*sorted(zip(distances, intersections)))
          return list(intersections), list(distances)
      else:
          return [], []
docs: Calculate the intersection points between a ray and multiple
      spheres.
  
      **Returns**
  
      intersections
      
      distances
      
      Ordered by closest to farther