def from_factors(cls, factors, frame=None): """Construct a scale transformation from scale factors. Parameters ---------- factors : list of float The scale factors along X, Y, Z. frame : :class:`compas.geometry.Frame`, optional The anchor frame for the scaling transformation. Defaults to ``None``. Returns ------- Scale A scale transformation. Examples -------- >>> point = Point(2, 5, 0) >>> frame = Frame(point, (1, 0, 0), (0, 1, 0)) >>> points = [point, Point(2, 10, 0)] >>> S = Scale.from_factors([2.] * 3, frame) >>> [p.transformed(S) for p in points] [Point(2.000, 5.000, 0.000), Point(2.000, 15.000, 0.000)] """ S = cls() if frame: Tw = matrix_from_frame(frame) Tl = matrix_inverse(Tw) Sc = matrix_from_scale_factors(factors) S.matrix = multiply_matrices(multiply_matrices(Tw, Sc), Tl) else: S.matrix = matrix_from_scale_factors(factors) return S
def __init__(self, matrix=None): if matrix: scale, _, _, _, _ = decompose_matrix(matrix) check = matrix_from_scale_factors(scale) if not allclose(flatten(matrix), flatten(check)): raise ValueError('This is not a proper scale matrix.') super(Scale, self).__init__(matrix=matrix)
def scale_points_xy(points, scale): """Scale points in the XY plane. Parameters ---------- points : list of point A list of points. scale : float A scaling factor. Returns ------- list of point The scaled points in the XY plane (Z=0). Examples -------- >>> """ T = matrix_from_scale_factors([scale, scale, 0]) return transform_points(points, T)
def scale_points_xy(points, scale): """Scale points in the XY plane. Parameters ---------- points : sequence[[float, float, float] | :class:`compas.geometry.Point`] A list of points. scale : float A scaling factor. Returns ------- list[[float, float, float]] The scaled points in the XY plane (Z=0). Examples -------- >>> """ T = matrix_from_scale_factors([scale, scale, 0]) return transform_points(points, T)
def __init__(self, scale_factors): self.matrix = matrix_from_scale_factors(scale_factors)
def test_matrix_from_scale_factors(): Sc = matrix_from_scale_factors([1, 2, 3]) assert Sc == [[1.0, 0.0, 0.0, 0.0], [0.0, 2.0, 0.0, 0.0], [0.0, 0.0, 3.0, 0.0], [0.0, 0.0, 0.0, 1.0]]