Esempio n. 1
0
    def test_computing_normal_on_translated_sphere(self):
        s = Sphere()
        s.set_transform(translation(0, 1, 0))

        n = s.normal_at(point(0, 1.70711, -0.70711))

        self.assert_tuple_equals(vector(0, 0.70711, -0.70711), n, 0.001)
    def test_the_view_trasnformation_move_the_world(self):
        from_where = point(0, 0, 8)
        to = point(0, 0, 0)
        up = vector(0, 1, 0)

        t = view_transform(from_where, to, up)

        self.assert_matrix_equals(translation(0, 0, -8), t)
Esempio n. 3
0
    def test_intersecting_translated_sphere_with_ray(self):
        r = Ray(point(0, 0, -5), vector(0, 0, 1))
        s = Sphere()

        s.set_transform(translation(5, 0, 0))
        xs = s.intersect(r)

        self.assertEqual(0, len(xs))
    def test_chain_transformation_must_be_applied_in_reverse_order(self):
        p = point(1, 0, 1)
        a = rotation_x(pi / 2)
        b = scaling(5, 5, 5)
        c = translation(10, 5, 7)

        t = c * b * a

        self.assertEqual(point(15, 0, 7), t * p)
Esempio n. 5
0
    def test_construct_ray_when_camera_is_transformed(self):
        c = Camera(201,
                   101,
                   pi / 2.0,
                   transform=rotation_y(pi / 4.0) * translation(0, -2, 5))
        r = ray_for_pixel(c, 100, 50)

        self.assert_tuple_equals(point(0, 2, -5), r.origin, 0.001)
        self.assert_tuple_equals(vector(sqrt(2) / 2, 0, -sqrt(2) / 2),
                                 r.direction, 0.001)
    def test_individual_transformation_are_applied_in_sequence(self):
        p = point(1, 0, 1)
        a = rotation_x(pi / 2)
        b = scaling(5, 5, 5)
        c = translation(10, 5, 7)

        p2 = a * p
        p3 = b * p2
        p4 = c * p3

        self.assertEqual(point(15, 0, 7), p4)
 def test_translation_does_not_affect_vectors(self):
     self.assertEqual(vector(-3, 4, 5),
                      translation(5, -3, 2) * vector(-3, 4, 5))
 def test_multiplying_by_inverse_of_translation(self):
     self.assertEqual(point(-8, 7, 3),
                      translation(5, -3, 2).inverse() * point(-3, 4, 5))
 def test_multiplying_by_translation_matrix(self):
     p = point(-3, 4, 5)
     self.assertEqual(point(2, 1, 7), translation(5, -3, 2) * p)
Esempio n. 10
0
 def test_translating_ray(self):
     r = Ray(point(1, 2, 3), vector(0, 1, 0))
     m = translation(3, 4, 5)
     r2 = r.transform(m)
     self.assertEqual(point(4, 6, 8), r2.origin)
     self.assertEqual(vector(0, 1, 0), r2.direction)
Esempio n. 11
0
from math import pi
from renderer.camera import Camera, render
from renderer.lights import PointLight
from renderer.materials import Material
from renderer.sphere import Sphere
from renderer.transformations import scaling, translation, rotation_y, rotation_x, view_transform
from renderer.tuples import point, color, vector
from renderer.world import World

floor = Sphere()
floor.transform = scaling(10, 0.01, 10)
floor.material.color = color(1, 0.9, 0.9)
floor.material.specular = 0

left_wall = Sphere()
left_wall.transform = translation(0, 0, 5) * rotation_y(-pi / 4) * rotation_x(
    pi / 2) * scaling(10, 0.01, 10)
left_wall.material.color = color(1, 0.9, 0.9)
left_wall.material.specular = 0

right_wall = Sphere()
right_wall.transform = translation(0, 0, 5) * rotation_y(pi / 4) * rotation_x(
    pi / 2) * scaling(10, 0.01, 10)
right_wall.material.color = color(1, 0.9, 0.9)
right_wall.material.specular = 0

middle = Sphere()
middle.transform = translation(-0.5, 1, 0.5)
middle.material.color = color(0.1, 1, 0.5)
middle.material.ambient = 0.1
middle.material.diffuse = 0.7
Esempio n. 12
0
 def test_set_transform(self):
     s = Sphere()
     t = translation(2, 3, 4)
     s.set_transform(t)
     self.assertEqual(t, s.transform)