예제 #1
0
 def test_cross_product(self):
     a = Direction.from_xyz((2.0, 3.0, 4.0))
     b = Direction.from_xyz((10.0, 100.0, 1000.0))
     expected_direction = Direction.from_xyz((
         3.0 * 1000.0 - 4.0 * 100.0,
         4.0 * 10.0 - 2.0 * 1000.0,
         2.0 * 100.0 - 3.0 * 10.0
     ))
     actual_direction = a.cross(b)
     self.assertTupleEqual(expected_direction.coordinates, actual_direction.coordinates)
     # cross product is orthoganal to arguments
     self.assertAlmostEqual(0.0, a.dot(actual_direction))
     self.assertAlmostEqual(0.0, b.dot(actual_direction))
예제 #2
0
 def setUp(self):
     self.clean_state()
     self.diameter = 0.1
     self.aperture_origin = Position.from_xyz((10.0, 20.0, 30.0))
     self.aperture_direction = Direction.from_xyz((1.0, 2.0, 3.0))
     self.placement = Ray(self.aperture_origin, self.aperture_direction.normalized())
     self.aperture = Aperture(placement=self.placement, diameter=self.diameter)
     self.initial_wavefront = WaveFront.unit_sphere
     self.orthogonal_directions = [
         self.aperture_direction.cross(Direction.right).normalized(),
         self.aperture_direction.cross(Direction.forward).normalized(),
         self.aperture_direction.cross(Direction.backward).normalized(),
     ]
예제 #3
0
 def setUp(self):
     self.clean_state()
     self.vector = (2.0, 3.0, 4.0)
     vector_length = vector_norm(self.vector)
     self.unit_vector = tuple(component / vector_length for component in self.vector)
     self.position = Position.from_xyz((10.0, 20.0, 30.0))
     self.direction = Direction.from_xyz(self.vector)
     self.unit_direction = Direction.from_xyz(self.unit_vector)
     self.ray = Ray(self.position, self.direction)
     self.unit_ray = Ray(self.position, self.unit_direction)
     self.other_position = Position.from_xyz((-9.0, -88.0, 12.34))
     self.other_direction = Direction.from_xyz((19.0, 8.0, -0.03))
     self.other_ray = Ray(self.other_position, self.other_direction)
     offset = self.position.dot(self.unit_direction)
     plane_projector = (-offset,) + self.unit_vector
     self.plane = Plane(plane_projector)
     self.orthogonal_directions = [
         Direction.from_xyz((0.2, 0.2, -0.25)),
         Direction.from_xyz((-7.0, 2.0, 2.0))
     ]
     self.orthogonal_rays = [Ray(self.position, direction)
                             for direction in self.orthogonal_directions]
예제 #4
0
 def setUp(self):
     self.clean_state()
     self.diameter = 10.0
     self.focal_length = 50.0
     self.aperture_origin = Position.from_xyz((10.0, 20.0, 30.0))
     self.aperture_direction = Direction.from_xyz((1.0, 2.0, 3.0))
     self.aperture_normal = self.aperture_direction.normalized()
     self.placement = Ray(self.aperture_origin, self.aperture_normal)
     self.orthogonal_directions = [
         self.aperture_direction.cross(Direction.right).normalized(),
         self.aperture_direction.cross(Direction.forward).normalized(),
         self.aperture_direction.cross(Direction.backward).normalized(),
     ]
     self.test_directions = [self.aperture_normal.add(
         orthogonal_direction.scale(0.1)).normalized() for orthogonal_direction in self.orthogonal_directions]
예제 #5
0
 def when_triangle_repositioned(self):
     self.test_direction = Direction.from_xyz((1000.0, 2000.0, 3000.0))
     self.triangle = self.triangle.add(self.test_direction)
예제 #6
0
 def setUp(self):
     self.clean_state()
     self.direction = Direction.from_xyz((2.0, 3.0, 4.0))
     self.volume = 10.0
예제 #7
0
 def when_direction_added_to_ray(self):
     self.ray = self.ray.add(Direction.from_xyz((100, 200, 300)))
예제 #8
0
 def setUp(self):
     self.clean_state()
     self.expected_position = Position.from_xyz((10.0, 20.0, 30.0))
     self.expected_direction = Direction.from_xyz((0.5, 0.4, 0.3))
     self.endpoint_xyz = (10.5, 20.4, 30.3)
     self.ten_scale_endpoint_xyz = (15.0, 24.0, 33.0)
예제 #9
0
 def test_direction_from_xyz_requires_3_tuple(self):
     with self.assertRaises(ValueError):
         Direction.from_xyz((0.0, 2.2, 3.3, 4.4))
예제 #10
0
 def test_direction_from_xyz_requires_tuple(self):
     with self.assertRaises(TypeError):
         Direction.from_xyz("wrong stuff")
예제 #11
0
 def when_direction_created_from_xyz(self):
     self.direction = Direction.from_xyz(self.xyz)