Esempio n. 1
0
 def test_rotate_point_z(self):
     p = Point(0, 1, 0)
     half_quarter = Transformations.rotation_z(math.pi / 4)
     full_quarter = Transformations.rotation_z(math.pi / 2)
     self.assertEqual(Matrix.multiply_tuple(half_quarter, p),
                      Point(-math.sqrt(2) / 2,
                            math.sqrt(2) / 2, 0))
     self.assertEqual(Matrix.multiply_tuple(full_quarter, p),
                      Point(-1, 0, 0))
Esempio n. 2
0
class Clock:

    if __name__ == '__main__':
        canvas_size = 300
        canvas = Canvas(canvas_size, canvas_size)
        color = Color(1, 1, 1)
        radius = canvas_size * 3 / 8
        scale = Transformations.scaling(radius, radius, 0)
        origin = Point(0, 0, 0)
        center_translation = Transformations.translation(
            canvas_size / 2, canvas_size / 2, 0)
        center = Matrix.multiply_tuple(center_translation, origin)

        hour = Point(0, 1, 0)  # twelve
        for _ in range(12):
            scaled_hour = Matrix.multiply_tuple(scale, hour)
            positioned_hour = scaled_hour + center
            canvas.write_pixel(round(positioned_hour.x),
                               round(canvas.height - positioned_hour.y), color)
            hour_rotation = Transformations.rotation_z(math.pi / 6)
            hour = Matrix.multiply_tuple(hour_rotation, hour)

        canvas.canvas_to_ppm()
Esempio n. 3
0
 def test_normal_transformed_sphere(self):
     s = Sphere()
     m = Transformations.scaling(1, 0.5, 1).dot(Transformations.rotation_z(math.pi / 5))
     s.transform = m
     n = s.normal_at(Point(0, math.sqrt(2) / 2, -(math.sqrt(2) / 2)))
     self.assertEqual(n, Vector(0, 0.97014, -0.24254))