def intersect(self, ray): """The ray t value of the first intersection point of the ray with self, or None if no intersection occurs""" hit = None q = self.centre - ray.start vDotQ = dot(ray.dir, q) squareDiffs = dot(q, q) - self.radius*self.radius discrim = vDotQ * vDotQ - squareDiffs if discrim >= 0: root = sqrt(discrim) t0 = (vDotQ - root) t1 = (vDotQ + root) if t0 < t1: hit = Hit(self, ray, t0, t1, None, self.material) else: hit = Hit(self, ray, t1, t0, None, self.material) if hit.entry > 0: hit.normal = self.normal(ray.pos(hit.entry)) if hit.exit > 0: hit.normal2 = self.normal(ray.pos(hit.exit)) return hit
def intersect(self, ray): """The ray t value of the first intersection point of the ray with self, or None if no intersection occurs""" hit = None q = self.centre - ray.start vDotQ = dot(ray.dir, q) squareDiffs = dot(q, q) - self.radius * self.radius discrim = vDotQ * vDotQ - squareDiffs if discrim >= 0: root = sqrt(discrim) t0 = (vDotQ - root) t1 = (vDotQ + root) if t0 < t1: hit = Hit(self, ray, t0, t1, None, self.material) else: hit = Hit(self, ray, t1, t0, None, self.material) if hit.entry > 0: hit.normal = self.normal(ray.pos(hit.entry)) if hit.exit > 0: hit.normal2 = self.normal(ray.pos(hit.exit)) return hit