def intersections(self,ray : Ray ): center_to_ray = ray.origin - self.origin # A is always 1 since vectors are normalized B = 2.0 * Utils.fast_dot(center_to_ray, ray.direction) center_to_ray_dot = Utils.fast_dot(center_to_ray, center_to_ray) C = center_to_ray_dot - self.radius**2.0 discriminant = (B**2.0) - 4.0*C if discriminant < 0: return (False,0,0) elif round(discriminant,3) == 0: return False, -B / 2.0 , sys.float_info.min else: return True, (-B + sqrt(discriminant))/2.0, (-B - sqrt(discriminant))/2.0
def phong_shading(light_ws, position_ws, normal): view = Utils.normalize(light_ws - position_ws) return Utils.fast_dot(view, normal)