def get_is_intersected(self, ray) -> bool: # ray from word_space_to_object_space ray_o = ray * self.worldToObject denominator = Vector3d.dot(self.normal, ray_o.direction) if math.fabs(denominator) < CONST_EPSILON: return False o = Vector3d.create_from_point3d(ray_o.origin) t = -(Vector3d.dot(self.normal, o) + self.distance) / denominator if ray_o.min_t <= t < ray_o.max_t: return True return False
def get_intersection(self, ray: Ray, dg: DifferentialGeometry) -> (bool, float): # ray from word_space_to_object_space ray_o = ray * self.worldToObject denominator = Vector3d.dot(self.normal, ray_o.direction) if math.fabs(denominator) < CONST_EPSILON: return False, 0.0 o = Vector3d.create_from_point3d(ray_o.origin) t = -(Vector3d.dot(self.normal, o) + self.distance) / denominator if ray_o.min_t <= t < ray_o.max_t: dg.point = ray_o.get_at(t) * self.objectToWorld dg.normal = self.normal * self.objectToWorld dg.shape = self return True, t return False, 0.0
def internal_solve(self, ray_l: Ray, ray_w: Ray) -> (float, float): o = Vector3d.create_from_point3d(ray_l.origin) a = Vector3d.dot(ray_l.direction, ray_l.direction) b = 2.0 * Vector3d.dot(ray_l.direction, o) c = Vector3d.dot(o, o) - self.radius_squared # Solve quadratic equation for _t_ values t0, t1 = maths.tools.get_solve_quadratic(a, b, c) if t0 is None and t1 is None: return None, None # Compute intersection distance along ray if t0 > ray_w.max_t or t1 < ray_w.min_t: return None, None thit = t0 if t0 < ray_w.min_t: thit = t1 if thit > ray_w.max_t: return None, None return t0, t1