Example #1
0
def test_transformed_group():
    g = Group()
    g.set_transform(Scaling(2, 2, 2))
    s = Sphere()
    s.set_transform(Translation(5, 0, 0))
    g.add_child(s)
    r = Ray(Point(10, 0, -10), Vector(0, 0, 1))
    xs = g.intersect(r)
    assert len(xs) == 2
Example #2
0
def test_world_to_object():
    g1 = Group()
    g1.set_transform(RotationY(math.pi / 2))
    g2 = Group()
    g2.set_transform(Scaling(2, 2, 2))
    g1.add_child(g2)
    s = Sphere()
    s.set_transform(Translation(5, 0, 0))
    g2.add_child(s)
    p = s.world_to_object(Point(-2, 0, -10))
    assert p == Point(0, 0, -1)
Example #3
0
def test_child_normal():
    g1 = Group()
    g1.set_transform(RotationY(math.pi / 2))
    g2 = Group()
    g2.set_transform(Scaling(1, 2, 3))
    g1.add_child(g2)
    s = Sphere()
    s.set_transform(Translation(5, 0, 0))
    g2.add_child(s)
    n = s.normal_at(Point(1.7321, 1.1547, -5.5774))
    assert n == Vector(0.2857, 0.4286, -0.8571)
Example #4
0
def test_normal_object_to_world():
    g1 = Group()
    g1.set_transform(RotationY(math.pi / 2))
    g2 = Group()
    g2.set_transform(Scaling(1, 2, 3))
    g1.add_child(g2)
    s = Sphere()
    s.set_transform(Translation(5, 0, 0))
    g2.add_child(s)
    n = s.normal_to_world(
        Vector(math.sqrt(3) / 3,
               math.sqrt(3) / 3,
               math.sqrt(3) / 3))
    assert n == Vector(0.2857, 0.4286, -0.8571)