def test_translate(self): vec_0 = get_vec_0() directions = get_directions(vec_0.units) for direction in directions: res_vec = geom.transform_vector(geom.translate(direction), vec_0) res = np.sum(res_vec - (direction + vec_0)) self.assertAlmostEqual(res, 0)
def test_rotate(self): vec_1 = get_vec_0() normalized = geom.normalize(vec_1) directions = get_directions(q.dimensionless) for direction in directions: rot_axis = np.cross(direction, normalized) * q.dimensionless trans_mat = geom.rotate(geom.angle(direction, normalized), rot_axis) diff = np.sum(normalized - geom.normalize(geom.transform_vector(trans_mat, direction))) self.assertAlmostEqual(diff, 0)
def test_scale(self): self.assertRaises(ValueError, geom.scale, np.array([0, 1, 2])) self.assertRaises(ValueError, geom.scale, np.array([1, -1, 2])) base = np.array([0.1, 0.25, 0.5, 0.75, 1.0, 1.5, 2.0]) coeffs = np.array(list(itertools.product(base, base, base))) vec_0 = get_vec_0() for coeff in coeffs: res_vec = geom.transform_vector(geom.scale(coeff), vec_0) res = np.sum(res_vec - (coeff * vec_0)) self.assertAlmostEqual(res, 0)
def test_rotate(self): vec_1 = get_vec_0() normalized = geom.normalize(vec_1) directions = get_directions(q.dimensionless) for direction in directions: rot_axis = np.cross(direction, normalized) * q.dimensionless trans_mat = geom.rotate(geom.angle(direction, normalized), rot_axis) diff = np.sum(normalized - geom.normalize( geom.transform_vector(trans_mat, direction))) self.assertAlmostEqual(diff, 0)
def _get_moved_bounding_box(self, body, angle): body.translate((1, 0, 0) * q.mm) body.rotate(angle, np.array((0, 0, 1))) body.translate((1, 0, 0) * q.mm) base = -2 * body.radius.magnitude, 2 * body.radius.magnitude transformed = [] for point in list(itertools.product(base, base, base)): transformed.append( geom.transform_vector(body.transform_matrix, point * body.radius.units).simplified.magnitude) return transformed * q.m
def bounding_box(self): """Bounding box of the metaball.""" radius = self.radius.simplified.magnitude base = -2 * radius, 2 * radius points = list(itertools.product(base, base, base)) * q.m # Transform by the current transformation matrix. transformed = [] for point in points: transformed.append( geom.transform_vector(self.transform_matrix, point)) return BoundingBox(np.array(transformed) * q.m)