def decomposed(self): """Decompose the `Transformation` into its components. Returns ------- :class:`compas.geometry.Scale` The scale component of the current transformation. :class:`compas.geometry.Shear` The shear component of the current transformation. :class:`compas.geometry.Rotation` The rotation component of the current transformation. :class:`compas.geometry.Translation` The translation component of the current transformation. :class:`compas.geometry.Projection` The projection component of the current transformation. Examples -------- >>> from compas.geometry import Scale, Translation, Rotation >>> trans1 = [1, 2, 3] >>> angle1 = [-2.142, 1.141, -0.142] >>> scale1 = [0.123, 2, 0.5] >>> T1 = Translation.from_vector(trans1) >>> R1 = Rotation.from_euler_angles(angle1) >>> S1 = Scale.from_factors(scale1) >>> M = T1 * R1 * S1 >>> S, H, R, T, P = M.decomposed() >>> S1 == S True >>> R1 == R True >>> T1 == T True """ from compas.geometry import Scale # noqa: F811 from compas.geometry import Shear from compas.geometry import Rotation # noqa: F811 from compas.geometry import Translation # noqa: F811 from compas.geometry import Projection s, h, a, t, p = decompose_matrix(self.matrix) S = Scale.from_factors(s) H = Shear.from_entries(h) R = Rotation.from_euler_angles(a, static=True, axes='xyz') T = Translation.from_vector(t) P = Projection.from_entries(p) return S, H, R, T, P
def decomposed(self): """Decompose the ``Transformation`` into its ``Scale``, ``Shear``, ``Rotation``, ``Translation`` and ``Perspective`` components. Returns ------- 5-tuple of Transformation The scale, shear, rotation, tranlation, and projection components of the current transformation. Examples -------- >>> trans1 = [1, 2, 3] >>> angle1 = [-2.142, 1.141, -0.142] >>> scale1 = [0.123, 2, 0.5] >>> T1 = Translation(trans1) >>> R1 = Rotation.from_euler_angles(angle1) >>> S1 = Scale(scale1) >>> M = (T1 * R1) * S1 >>> Sc, Sh, R, T, P = M.decomposed() >>> S1 == Sc True >>> R1 == R True >>> T1 == T True """ from compas.geometry import Scale # noqa: F811 from compas.geometry import Shear from compas.geometry import Rotation # noqa: F811 from compas.geometry import Translation # noqa: F811 from compas.geometry import Projection sc, sh, a, t, p = decompose_matrix(self.matrix) Sc = Scale(sc) Sh = Shear.from_entries(sh) R = Rotation.from_euler_angles(a, static=True, axes='xyz') T = Translation(t) P = Projection.from_entries(p) return Sc, Sh, R, T, P
def test_from_entries(): shear1 = [-0.41, -0.14, -0.35] S = Shear.from_entries(shear1) s = [[1.0, -0.41, -0.14, 0.0], [0.0, 1.0, -0.35, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]] assert np.allclose(S, s)
def from_entries(cls, shear_entries): """Creates a ``Shear`` from the 3 factors for x-y, x-z, and y-z axes. Parameters ---------- shear_factors : :obj:`list` of :obj:`float` The 3 shear factors for x-y, x-z, and y-z axes. Examples -------- >>> S = Shear.from_entries([1, 2, 3]) """ M = matrix_from_shear_entries(shear_entries) return cls.from_matrix(M) # ============================================================================== # Main # ============================================================================== if __name__ == "__main__": from compas.geometry import Frame from compas.geometry import Shear shear1 = [-0.41, -0.14, -0.35] Sh1 = Shear.from_entries(shear1) S2, Sh, R2, T2, P = Sh1.decompose() print(Sh)