Exemple #1
0
 def test_under_point_offset_below_surface(self):
     r = Ray(Point(0, 0, -5), Vector(0, 0, 1))
     shape = GlassSphere()
     shape.transform = Transformations.translation(0, 0, 1)
     i = Intersection(5, shape)
     xs = Intersection.intersections(i)
     comps = Computations.prepare_computations(i, r, xs)
     self.assertGreater(comps.under_point.z, Constants.epsilon / 2)
     self.assertLess(comps.point.z, comps.under_point.z)
Exemple #2
0
 def test_findinf_n1_n2_at_various_intersections(self):
     a = GlassSphere()
     a.transform = Transformations.scaling(2, 2, 2)
     a.material.refractive_index = 1.5
     b = GlassSphere()
     b.transform = Transformations.translation(0, 0, -0.25)
     b.material.refractive_index = 2.0
     c = GlassSphere()
     c.transform = Transformations.translation(0, 0, 0.25)
     c.material.refractive_index = 2.5
     r = Ray(Point(0, 0, -4), Vector(0, 0, 1))
     xs = Intersection.intersections(Intersection(2, a), Intersection(2.75, b), Intersection(3.25, c), Intersection(4.75, b), Intersection(5.25, c), Intersection(6, a))
     RefractiveIndices = namedtuple("RefractiveIndices", ["n1", "n2"])
     refractive_indices_list = [
         RefractiveIndices(1.0, 1.5),
         RefractiveIndices(1.5, 2.0),
         RefractiveIndices(2.0, 2.5),
         RefractiveIndices(2.5, 2.5),
         RefractiveIndices(2.5, 1.5),
         RefractiveIndices(1.5, 1.0)
     ]
     for index, refractive_index in enumerate(refractive_indices_list):
         comps = Computations.prepare_computations(xs[index], r, xs)
         print(comps.n1)
         print(comps.n2)
         self.assertEqual(comps.n1, refractive_index.n1)
         self.assertEqual(comps.n2, refractive_index.n2)
 def test_under_point1(self):
     r = Ray(Point(0, 0, -5), Vector(0, 0, 1))
     shape = GlassSphere()
     shape.set_transform(translate(0, 0, 1))
     i = Intersection(5, shape)
     xs = Intersections([i])
     comps = i.prepare_computations(r, xs)
     # print(comps.normalv)
     # print(comps.point)
     # print(comps.under_point.z)
     self.assertTrue(comps.under_point.z > EPSILON / 2)
     self.assertTrue(comps.point.z < comps.under_point.z)
Exemple #4
0
 def test_schlick_approximation_with_small_angle(self):
     shape = GlassSphere()
     r = Ray(Point(0, 0.99, -2), Vector(0, 0, 1))
     xs = Intersection.intersections(Intersection(1.8589, shape))
     comps = Computations.prepare_computations(xs[0], r, xs)
     reflectance = World.schlick(comps)
     self.assertAlmostEqual(reflectance, 0.48873, delta = Constants.epsilon)
Exemple #5
0
 def test_schlick_approximation_with_perpendicular_viewing_angle(self):
     shape = GlassSphere()
     r = Ray(Point(0, 0, 0), Vector(0, 1, 0))
     xs = Intersection.intersections(Intersection(-1,shape), Intersection(1, shape))
     comps = Computations.prepare_computations(xs[1], r, xs)
     reflectance = World.schlick(comps)
     self.assertAlmostEqual(reflectance, 0.04, delta = Constants.epsilon)
Exemple #6
0
 def test_schlick_approximation_under_total_internal_reflection(self):
     shape = GlassSphere()
     r = Ray(Point(0, 0, math.sqrt(2) / 2), Vector(0, 1, 0))
     xs = Intersection.intersections(Intersection(-math.sqrt(2) / 2, shape), Intersection(math.sqrt(2) / 2, shape))
     comps = Computations.prepare_computations(xs[1], r, xs)
     reflectance = World.schlick(comps)
     self.assertEqual(reflectance, 1.0)
 def test_schlick_approximation_with_small_angle_and_n2_larger_than_n1(self):
     shape = GlassSphere()
     r = Ray(Point(0, 0.99, -2), Vector(0, 0, 1))
     ls = [
         Intersection(1.8589, shape),
     ]
     xs = Intersections(ls)
     comps = xs[0].prepare_computations(r, xs)
     reflectance = comps.schlick()
     self.assertTrue(equals(reflectance, 0.48873))
 def test_schlick_approximation_with_perpendicular_viewing_angle(self):
     shape = GlassSphere()
     r = Ray(Point(0, 0, 0), Vector(0, 1, 0))
     ls = [
         Intersection(-1, shape),
         Intersection(1, shape)
     ]
     xs = Intersections(ls)
     comps = xs[1].prepare_computations(r, xs)
     reflectance = comps.schlick()
     self.assertTrue(equals(reflectance, 0.04))
 def test_schlick_approximation_under_total_internal_reflection(self):
     shape = GlassSphere()
     r = Ray(Point(0, 0, sqrt(2)/2), Vector(0, 1, 0))
     ls = [
         Intersection(-sqrt(2)/2, shape),
         Intersection(sqrt(2)/2, shape)
     ]
     xs = Intersections(ls)
     comps = xs[1].prepare_computations(r, xs)
     reflectance = comps.schlick()
     self.assertTrue(equals(reflectance, 1.0))
Exemple #10
0
 def test_sphere_glassy_material(self):
     s = GlassSphere()
     self.assertTrue(np.array_equal(s.transform, np.identity(4)))
     self.assertEqual(s.material.transparency, 1.0)
     self.assertEqual(s.material.refractive_index, 1.5)
    def test_refract1(self):
        A = GlassSphere()
        A.set_transform(scale(2, 2, 2))
        A.material.refractive_index = 1.5

        B = GlassSphere()
        B.set_transform(translate(0, 0, -0.25))
        B.material.refractive_index = 2.0

        C = GlassSphere()
        C.set_transform(translate(0, 0, 0.25))
        C.material.refractive_index = 2.5

        r = Ray(Point(0, 0, -4), Vector(0, 0, 1))

        ls = [
            Intersection(2, A),
            Intersection(2.75, B),
            Intersection(3.25, C),
            Intersection(4.75, B),
            Intersection(5.25, C),
            Intersection(6, A)
        ]
        xs = Intersections(ls)

        comps0 = xs[0].prepare_computations(r, xs)
        self.assertEqual(comps0.n1, 1.0)
        self.assertEqual(comps0.n2, 1.5)

        comps1 = xs[1].prepare_computations(r, xs)
        self.assertEqual(comps1.n1, 1.5)
        self.assertEqual(comps1.n2, 2.0)

        comps2 = xs[2].prepare_computations(r, xs)
        self.assertEqual(comps2.n1, 2.0)
        self.assertEqual(comps2.n2, 2.5)

        comps3 = xs[3].prepare_computations(r, xs)
        self.assertEqual(comps3.n1, 2.5)
        self.assertEqual(comps3.n2, 2.5)

        comps4 = xs[4].prepare_computations(r, xs)
        self.assertEqual(comps4.n1, 2.5)
        self.assertEqual(comps4.n2, 1.5)

        comps5 = xs[5].prepare_computations(r, xs)
        self.assertEqual(comps5.n1, 1.5)
        self.assertEqual(comps5.n2, 1.0)
 def test_default1(self):
     s = GlassSphere()
     self.assertTrue(matrix.equals(I(), s.transform))
     self.assertEqual(s.material.transparency, 1.0)
     self.assertEqual(s.material.refractive_index, 1.5)