Skip to content

Instantly share code, notes, and snippets.

@omaraflak
Last active July 23, 2020 14:24
Show Gist options
  • Save omaraflak/40947c628bc94ce6306431ae17a71bb7 to your computer and use it in GitHub Desktop.
Save omaraflak/40947c628bc94ce6306431ae17a71bb7 to your computer and use it in GitHub Desktop.
def nearest_intersected_object(objects, ray_origin, ray_direction):
distances = [sphere_intersect(obj['center'], obj['radius'], ray_origin, ray_direction) for obj in objects]
nearest_object = None
min_distance = np.inf
for index, distance in enumerate(distances):
if distance and distance < min_distance:
min_distance = distance
nearest_object = objects[index]
return nearest_object, min_distance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment