def test_properties(self): # Defaults plane = geometry.Plane() self.assertSameArray(np.array([0, 0, 1]), plane.normal()) # Normalizes normals = [ np.array([0, 0, 7]), np.array([0, 0, 23.6]), np.array([0, .0, -2.47]) ] for n in normals: plane = geometry.Plane(normal=n) self.assertAlmostEqual(1, _utils.vabs(plane.normal())) plane = geometry.Plane(pos=np.array([-0.5, -0.5, 1])) ray = rays.Ray() ray.k = np.array([0, 0, 1]) self.assertSameArray(np.array([0, 0, 1]), plane.intersect(ray)) ray = rays.Ray() ray.k = np.array([1, 1, 0]) self.assertSameArray(None, plane.intersect(ray)) ray = rays.Ray() ray.k = np.array([0, 0, -1]) self.assertSameArray(None, plane.intersect(ray))
def test_intersect_axis(self): ray = rays.Ray(k=_utils.vec(0, 0, 1)) origin = _utils.pos(1, 0, 1) axis = _utils.vec(0, 1, 0) pt_ray, pt_axi = ray.intersect_axis(origin, axis) self.assertApproxArray(pt_ray, _utils.pos(0, 0, 1)) self.assertApproxArray(pt_axi, _utils.pos(1, 0, 1)) self.assertAlmostEqual(_utils.vabs(pt_ray - pt_axi), 1)
def test_properties(self): sphere = geometry.Sphere(1, 1, 1, axis=np.array([3, 5, 8])) self.assertEqual(_utils.vabs(sphere._Sphere__axi), 1) with self.assertRaises(ValueError): geometry.Sphere(1, 2, 1) with self.assertRaises(ValueError): geometry.Sphere(1, 1, 2) with self.assertRaises(TypeError): geometry.Sphere(True, None, "Happy")
def test_properties(self): origin = np.array([1, 2, 3], dtype=float) ray = rays.Ray(origin=origin) self.assertSameArray(ray.pos, origin) ray.k = origin * 3 self.assertSameArray(ray.k, origin / _utils.vabs(origin)) ray.pos = origin + origin self.assertTrue(len(ray) == 2) self.assertSameArray(ray.pos, ray[-1]) self.assertEqual(len(ray), len(ray.path)) self.assertSameArray(ray[0], ray.path[0]) freq = 7.9 ray.frequency = freq self.assertAlmostEqual(freq, ray.frequency) with self.assertRaises(TypeError): ray.k = [1, 2, 3] with self.assertRaises(TypeError): ray.pos = 6.4
def test_vabs(self): arr = np.array([5, 0, 0]) self.assertEqual(_utils.vabs(arr), 5) arr = np.array([2, 2, 1]) self.assertEqual(_utils.vabs(arr), 3)
def angle(a, b): return np.arccos(abs(a.dot(b) / _utils.vabs(a) / _utils.vabs(b)))
def __init__(self, geo_obj, normal=_utils.vec(0, 0, 1)): self._obj = geo_obj self._normal = normal / _utils.vabs(normal)