def test_shear(): angle = 1 direction = [1, 0, 0] point = [1, 1, 1] normal = [0, 0, 1] S = Shear.from_angle_direction_plane(angle, direction, (point, normal)) s = [[1.0, 0.0, 1.557407724654902, -1.557407724654902], [0.0, 1.0, 0.0, -0.0], [0.0, 0.0, 1.0, -0.0], [0.0, 0.0, 0.0, 1.0]] assert allclose(S.matrix, s)
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
from compas.geometry import Scale from compas.geometry import Reflection from compas.geometry import Projection from compas.geometry import Shear axis, angle = [0.2, 0.4, 0.1], 0.3 R = Rotation.from_axis_and_angle(axis, angle) print("Rotation:\n", R) translation_vector = [5, 3, 1] T = Translation(translation_vector) print("Translation:\n", T) scale_factors = [0.1, 0.3, 0.4] S = Scale(scale_factors) print("Scale:\n", S) point, normal = [0.3, 0.2, 1], [0.3, 0.1, 1] R = Reflection(point, normal) print("Reflection:\n", R) point, normal = [0, 0, 0], [0, 0, 1] perspective = [1, 1, 0] P = Projection.perspective(point, normal, perspective) print("Perspective projection:\n", R) angle, direction = 0.1, [0.1, 0.2, 0.3] point, normal = [4, 3, 1], [-0.11, 0.31, -0.17] S = Shear(angle, direction, point, normal) print("Shear:\n", S)
from compas.geometry import Scale from compas.geometry import Reflection from compas.geometry import Projection from compas.geometry import Shear axis, angle = [0.2, 0.4, 0.1], 0.3 R = Rotation.from_axis_and_angle(axis, angle) print("Rotation:\n", R) translation_vector = [5, 3, 1] T = Translation.from_vector(translation_vector) print("Translation:\n", T) scale_factors = [0.1, 0.3, 0.4] S = Scale.from_factors(scale_factors) print("Scale:\n", S) point, normal = [0.3, 0.2, 1], [0.3, 0.1, 1] R = Reflection.from_plane((point, normal)) print("Reflection:\n", R) point, normal = [0, 0, 0], [0, 0, 1] perspective = [1, 1, 0] P = Projection.from_plane_and_point((point, normal), perspective) print("Perspective projection:\n", R) angle, direction = 0.1, [0.1, 0.2, 0.3] point, normal = [4, 3, 1], [-0.11, 0.31, -0.17] S = Shear.from_angle_direction_plane(angle, direction, (point, normal)) print("Shear:\n", S)
def test_shear(): S = Shear(1) s = [[1.0, 0.0, 1.557407724654902, -1.557407724654902], [0.0, 1.0, 0.0, -0.0], [0.0, 0.0, 1.0, -0.0], [0.0, 0.0, 0.0, 1.0]] assert np.allclose(S, s)
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)