fix bugs, first working version

This commit is contained in:
2023-10-30 15:09:10 -04:00
parent 10c03e4651
commit 10e9d6775e
6 changed files with 37059 additions and 394 deletions
+11 -3
View File
@@ -48,12 +48,20 @@ class Disk(Shapes):
if discriminant < 0:
return None, None # 没有交点
else:
if np.dot(oc, oc) <= self.radius * self.radius + 1e-10:
dis2 = np.dot(oc,oc)
epsilon = 1e-12
if dis2 > 1 - epsilon and dis2 < 1 + epsilon:
normal = self.get_normal(ray.origin)
if np.dot(normal, ray.direction) < 0:
t = (-b + np.sqrt(discriminant)) / (2.0 * a)
else:
return None, None
elif dis2 <= 1 - epsilon:
t = (-b + np.sqrt(discriminant)) / (2.0 * a)
else:
t = (-b - np.sqrt(discriminant)) / (2.0 * a)
if t < 0:
return None, None
if t < 0:
return None, None
intersection_point = ray.origin + t * ray.direction
intersection_point = self.center + self.radius * (intersection_point - self.center)/np.linalg.norm(intersection_point - self.center)
return t,intersection_point