def test_2dtriangle(self): s = coord.Simplex([[0, 1], [1, 1], [1, 0]]) self.assertArrayAlmostEqual(s.bary_coords([0.5, 0.5]), [0.5, 0, 0.5]) self.assertArrayAlmostEqual(s.bary_coords([0.5, 1]), [0.5, 0.5, 0]) self.assertArrayAlmostEqual(s.bary_coords([0.5, 0.75]), [0.5, 0.25, 0.25]) self.assertArrayAlmostEqual(s.bary_coords([0.75, 0.75]), [0.25, 0.5, 0.25]) s = coord.Simplex([[1, 1], [1, 0]]) self.assertRaises(ValueError, s.bary_coords, [0.5, 0.5])
def test_bary_coords(self): s = coord.Simplex([[0, 2], [3, 1], [1, 0]]) point = [0.7, 0.5] bc = s.bary_coords(point) self.assertArrayAlmostEqual(bc, [0.26, -0.02, 0.76]) new_point = s.point_from_bary_coords(bc) self.assertArrayAlmostEqual(point, new_point)
def setUp(self): coords = [] coords.append([0, 0, 0]) coords.append([0, 1, 0]) coords.append([0, 0, 1]) coords.append([1, 0, 0]) self.simplex = coord.Simplex(coords)
def test_intersection(self): # simple test, with 2 intersections at faces s = coord.Simplex([[0, 2], [3, 1], [1, 0]]) point1 = [0.7, 0.5] point2 = [0.5, 0.7] intersections = s.line_intersection(point1, point2) expected = np.array([[1.13333333, 0.06666667], [0.8, 0.4]]) self.assertArrayAlmostEqual(intersections, expected) # intersection through point and face point1 = [0, 2] # simplex point point2 = [1, 1] # inside simplex expected = np.array([[1.66666667, 0.33333333], [0, 2]]) intersections = s.line_intersection(point1, point2) self.assertArrayAlmostEqual(intersections, expected) # intersection through point only point1 = [0, 2] # simplex point point2 = [0.5, 0.7] expected = np.array([[0, 2]]) intersections = s.line_intersection(point1, point2) self.assertArrayAlmostEqual(intersections, expected) # 3d intersection through edge and face point1 = [0.5, 0, 0] # edge point point2 = [0.5, 0.5, 0.5] # in simplex expected = np.array([[0.5, 0.25, 0.25], [0.5, 0.0, 0.0]]) intersections = self.simplex.line_intersection(point1, point2) self.assertArrayAlmostEqual(intersections, expected) # 3d intersection through edge only point1 = [0.5, 0, 0] # edge point point2 = [0.5, 0.5, -0.5] # outside simplex expected = np.array([[0.5, 0.0, 0.0]]) intersections = self.simplex.line_intersection(point1, point2) self.assertArrayAlmostEqual(intersections, expected) # coplanar to face (no intersection) point1 = [-1, 2] point2 = [0, 0] expected = np.array([]) intersections = s.line_intersection(point1, point2) self.assertArrayAlmostEqual(intersections, expected) # coplanar to face (with intersection line) point1 = [0, 2] # simplex point point2 = [1, 0] expected = np.array([[1, 0], [0, 2]]) intersections = s.line_intersection(point1, point2) self.assertArrayAlmostEqual(intersections, expected) # coplanar to face (with intersection points) point1 = [0.1, 2] point2 = [1.1, 0] expected = np.array([[1.08, 0.04], [0.12, 1.96]]) intersections = s.line_intersection(point1, point2) self.assertArrayAlmostEqual(intersections, expected)
def test_equal(self): c2 = list(self.simplex.coords) random.shuffle(c2) self.assertEqual(coord.Simplex(c2), self.simplex)