def test_the_normal_is_a_normalized_vector(): # Given s = Sphere() # When n = s.normal_at(Point(sqrt(3) / 3, sqrt(3) / 3, sqrt(3) / 3)) # Then assert n == n.normalize()
def test_the_normal_on_a_sphere_at_a_point_at_a_nonaxial_axis(): # Given s = Sphere() # When n = s.normal_at(Point(sqrt(3) / 3, sqrt(3) / 3, sqrt(3) / 3)) # Then assert n == Vector(sqrt(3) / 3, sqrt(3) / 3, sqrt(3) / 3)
def test_the_normal_on_a_sphere_at_a_point_on_the_z_axis(): # Given s = Sphere() # When n = s.normal_at(Point(0, 0, 1)) # Then assert n == Vector(0, 0, 1)
def test_computing_the_normal_on_a_translated_sphere(): # Given s = Sphere() s.transform = translation(0, 1, 0) # When n = s.normal_at(Point(0, 1.70711, -0.70711)) # Then assert n == Vector(0, 0.70711, -0.70711)
def test_commputing_the_normal_on_a_transformed_sphere(): # Given s = Sphere() m = scaling(1, 0.5, 1) * rotation_z(pi / 5) s.transform = m # When n = s.normal_at(Point(0, sqrt(2) / 2, -sqrt(2) / 2)) # Then assert n == Vector(0, 0.97014, -0.24254)
def test_finding_the_normal_on_a_child_object(): # Given g1 = Group() g1.transform = rotation_y(pi / 2) g2 = Group() g2.transform = scaling(1, 2, 3) g1.add_child(g2) s = Sphere() s.transform = translation(5, 0, 0) g2.add_child(s) # When n = s.normal_at(Point(1.7321, 1.1547, -5.5774)) # Then assert n == Vector(0.2857, 0.42854, -0.85716)