Example #1
0
    def testIntersection(self):
        
        phongRed = Phong(Point3(.8, .1, .1), Point3(.9, .9, .9), 2.0)
        testSphere = Sphere(Point3(0.0, 3.0, 0.0), 1.0, phongRed)

        intersection1 = testSphere.findIntersection(Point3(0, 0, 0), Vector3(0, 1, 0))

        self.assertTrue(intersection1.x == 0)
        self.assertTrue(intersection1.y == 2.0)
        self.assertTrue(intersection1.z == 0)

        intersection2 = testSphere.findIntersection(Point3(0, 8, 0), Vector3(0, -.5, 0))

        self.assertTrue(intersection2.x == 0)
        self.assertTrue(intersection2.y == 4.0)
        self.assertTrue(intersection2.z == 0)

        intersection3 = testSphere.findIntersection(Point3(5, 3, 0), Vector3(-10, 0, 0))

        self.assertTrue(intersection3.x == 1.0)
        self.assertTrue(intersection3.y == 3.0)
        self.assertTrue(intersection3.z == 0)

        intersection4 = testSphere.findIntersection(Point3(0, 3, -5), Vector3(0, 0, 2))

        self.assertTrue(intersection4.x == 0.0)
        self.assertTrue(intersection4.y == 3.0)
        self.assertTrue(intersection4.z == -1.0)

        intersection5 = testSphere.findIntersection(Point3(0, 3, -5), Vector3(0, 0, -2))

        self.assertTrue(intersection5.x == float('inf'))
        self.assertTrue(intersection5.y == float('inf'))
        self.assertTrue(intersection5.z == float('inf'))
Example #2
0
    def testNormal(self):
        
        phongRed = Phong(Point3(.8, .1, .1), Point3(.9, .9, .9), 2.0)
        testSphere = Sphere(Point3(1.0, -3.0, 0.0), 1.0, phongRed)

        intersection1 = testSphere.findIntersection(Point3(1.0, 0, 0), Vector3(0, -1, 0))

        normal1 = testSphere.getNormal(intersection1)

        self.assertTrue(normal1.x == 0.0)
        self.assertTrue(normal1.y == 1.0)
        self.assertTrue(normal1.z == 0.0)