예제 #1
0
 def normal_at(self, p):
     transformation = invert(self.transformation)
     object_point = transformation(p)
     object_normal = object_point - point(0, 0, 0)
     world_normal = transpose(transformation)(object_normal)
     world_normal[3] = 0
     return normalize(world_normal)
def test_the_inverse_of_an_x_rotation_rotates_in_the_opposite_direction():
    p = point(0, 1, 0)
    half_quarter = transformations.rotation_x(math.pi / 4)
    inverse = transformations.invert(half_quarter)

    assert (np.allclose(point(0,
                              math.sqrt(2) / 2, -math.sqrt(2) / 2),
                        inverse(p)))
def test_multiplying_the_inverse_of_a_scaling_matrix():
    transform = transformations.scaling(2, 3, 4)
    inverse = transformations.invert(transform)
    v = vector(-4, 6, 8)

    expected = vector(-2, 2, 2)
    actual = inverse(v)
    assert ((expected == actual).all())
예제 #4
0
 def intersect(self, ray):
     transformation = invert(self.transformation)
     transformed_ray = ray.transform(transformation)
     ts = intersect_fast(transformed_ray.origin, transformed_ray.direction)
     if len(ts) == 2:
         i1 = Intersection(ts[0], self)
         i2 = Intersection(ts[1], self)
         return Intersections(i1, i2)
     return []
예제 #5
0
    def ray_for_pixel(self, px, py):
        xoffset = (px + 0.5) * self.pixel_size
        yoffset = (py + 0.5) * self.pixel_size

        world_x = self._half_width - xoffset
        world_y = self._half_height - yoffset

        inverse_camera_transform = invert(self._transform)
        pixel = inverse_camera_transform(point(world_x, world_y, -1))
        origin = inverse_camera_transform(point(0, 0, 0))
        direction = normalize(pixel - origin)

        return Ray(origin, direction)
def test_multiplying_by_the_inverse_of_a_translation_matrix():
    transform = transformations.translation(5, -3, 2)
    transform = transformations.invert(transform)
    p = point(-3, 4, 5)

    assert ((point(-8, 7, 3) == transform(p)).all())