Last active
July 23, 2020 13:52
-
-
Save omaraflak/3ccc990dba3898def73252a6b0ef33d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sphere_intersect(center, radius, ray_origin, ray_direction): | |
b = 2 * np.dot(ray_direction, ray_origin - center) | |
c = np.linalg.norm(ray_origin - center) ** 2 - radius ** 2 | |
delta = b ** 2 - 4 * c | |
if delta > 0: | |
t1 = (-b + np.sqrt(delta)) / 2 | |
t2 = (-b - np.sqrt(delta)) / 2 | |
if t1 > 0 and t2 > 0: | |
return min(t1, t2) | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment