Exemple #1
0
 def test_intersect_cone_with_ray_parallel_to_half(self):
     shape = Cone()
     direction = Vector.normalize(Vector(0, 1, 1))
     r = Ray(Point(0, 0, -1), direction)
     xs = shape.local_intersect(r)
     self.assertEqual(len(xs), 1)
     self.assertAlmostEqual(xs[0].t, 0.35355, delta=Constants.epsilon)
Exemple #2
0
 def test_intersect_cone_end_cap(self):
     shape = Cone()
     shape.minimum = -0.5
     shape.maximum = 0.5
     shape.closed = True
     RayIntersection = namedtuple("RayIntersection",
                                  ["origin", "direction", "count"])
     ray_intersections = [
         RayIntersection(Point(0, 0, -5), Vector(0, 1, 0), 0),
         RayIntersection(Point(0, 0, -0.25), Vector(0, 1, 1), 2),
         RayIntersection(Point(0, 0, -0.25), Vector(0, 1, 0), 4)
     ]
     for ray_intersection in ray_intersections:
         direction = Vector.normalize(ray_intersection.direction)
         r = Ray(ray_intersection.origin, direction)
         xs = shape.local_intersect(r)
         self.assertEqual(len(xs), ray_intersection.count)
Exemple #3
0
 def test_intersect_cone_with_ray(self):
     shape = Cone()
     RayIntersection = namedtuple("RayIntersection",
                                  ["origin", "direction", "t0", "t1"])
     ray_intersections = [
         RayIntersection(Point(0, 0, -5), Vector(0, 0, 1), 5, 5),
         RayIntersection(Point(0, 0, -5), Vector(1, 1, 1), 8.66025,
                         8.66025),
         RayIntersection(Point(1, 1, -5), Vector(-0.5, -1, 1), 4.55006,
                         49.44994)
     ]
     for ray_intersection in ray_intersections:
         direction = Vector.normalize(ray_intersection.direction)
         r = Ray(ray_intersection.origin, direction)
         xs = shape.local_intersect(r)
         self.assertEqual(len(xs), 2)
         self.assertAlmostEqual(xs[0].t,
                                ray_intersection.t0,
                                delta=Constants.epsilon)
         self.assertAlmostEqual(xs[1].t,
                                ray_intersection.t1,
                                delta=Constants.epsilon)