fix bugs, first working version
This commit is contained in:
+11
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user