def test_normal_with_transform(self): s = Sphere() s.transform = Matrix.translate(0, 5, 0) n = s.normal(Point(1, 5, 0)) self.assertEqual(n, Vector(1, 0, 0)) s = Sphere() s.transform = Matrix.scale(1, 0.5, 1) r = math.sqrt(2) / 2 n = s.normal(Point(0, r, -r)) self.assertTupleEqual(n, Vector(0, 0.97014, -0.24254))
def test_normal(self): s = Sphere() n = s.normal(Point(1, 0, 0)) self.assertEqual(n, Vector(1, 0, 0)) n = s.normal(Point(0, 1, 0)) self.assertEqual(n, Vector(0, 1, 0)) n = s.normal(Point(0, 0, 1)) self.assertEqual(n, Vector(0, 0, 1)) r = math.sqrt(3) / 3 n = s.normal(Point(r, r, r)) self.assertEqual(n, Vector(r, r, r)) self.assertEqual(n, n.norm())