def test_basis_vectors():
    ea1 = 1.4, 0.5, 2.3
    args = False, 'xyz'
    R1 = Rotation.from_euler_angles(ea1, *args)
    R2 = [[-0.5847122176808724, -0.18803656702967916, 0.789147560317086],
          [-0.6544178905170501, -0.4655532858863264, -0.5958165511058404]]
    assert np.allclose(R1.basis_vectors, R2)
Esempio n. 2
0
 def vertex_xyz(self):
     """dict : The view coordinates of the volmesh object."""
     origin = Point(0, 0, 0)
     stack = []
     if self.scale != 1.0:
         S = Scale.from_factors([self.scale] * 3)
         stack.append(S)
     if self.rotation != [0, 0, 0]:
         R = Rotation.from_euler_angles(self.rotation)
         stack.append(R)
     if self.location != origin:
         if self.anchor is not None:
             xyz = self.volmesh.vertex_attributes(self.anchor, 'xyz')
             point = Point(*xyz)
             T1 = Translation.from_vector(origin - point)
             stack.insert(0, T1)
         T2 = Translation.from_vector(self.location)
         stack.append(T2)
     if stack:
         X = reduce(mul, stack[::-1])
         volmesh = self.volmesh.transformed(X)
     else:
         volmesh = self.volmesh
     vertex_xyz = {
         vertex: volmesh.vertex_attributes(vertex, 'xyz')
         for vertex in volmesh.vertices()
     }
     return vertex_xyz
def concatenate():
    trans1 = [1, 2, 3]
    angle1 = [-2.142, 1.141, -0.142]
    T1 = Translation(trans1)
    R1 = Rotation.from_euler_angles(angle1)
    M1 = T1.concatenate(R1)
    assert np.allclose(M1, T1 * R1)
Esempio n. 4
0
def test_concatenated():
    trans1 = [1, 2, 3]
    angle1 = [-2.142, 1.141, -0.142]
    T1 = Translation.from_vector(trans1)
    R1 = Rotation.from_euler_angles(angle1)
    M1 = T1.concatenated(R1)
    assert allclose(M1, T1 * R1)
Esempio n. 5
0
 def node_xyz(self):
     """dict : The view coordinates of the mesh object."""
     origin = Point(0, 0, 0)
     stack = []
     if self.scale != 1.0:
         S = Scale.from_factors([self.scale] * 3)
         stack.append(S)
     if self.rotation != [0, 0, 0]:
         R = Rotation.from_euler_angles(self.rotation)
         stack.append(R)
     if self.location != origin:
         if self.anchor is not None:
             xyz = self.network.vertex_attributes(self.anchor, 'xyz')
             point = Point(*xyz)
             T1 = Translation.from_vector(origin - point)
             stack.insert(0, T1)
         T2 = Translation.from_vector(self.location)
         stack.append(T2)
     if stack:
         X = reduce(mul, stack[::-1])
         network = self.network.transformed(X)
     else:
         network = self.network
     node_xyz = {
         network: network.node_attributes(node, 'xyz')
         for node in network.nodes()
     }
     return node_xyz
def test_rotation():
    angle1 = [-2.142, 1.141, -0.142]
    R = Rotation.from_euler_angles(angle1)
    r = [[0.41249169135312663, -0.8335562904208867, -0.3674704277413451, 0.0],
         [-0.05897071585157175, -0.4269749553355485, 0.9023385407861949, 0.0],
         [-0.9090506362335324, -0.35053715668381935, -0.22527903264048646, 0.0],
         [0.0, 0.0, 0.0, 1.0]]
    assert np.allclose(R, r)
Esempio n. 7
0
 def vertex_xyz(self):
     """dict : The view coordinates of the mesh object."""
     origin = Point(0, 0, 0)
     if self.anchor is not None:
         xyz = self.mesh.vertex_attributes(self.anchor, 'xyz')
         point = Point(* xyz)
         T1 = Translation.from_vector(origin - point)
         S = Scale.from_factors([self.scale] * 3)
         R = Rotation.from_euler_angles(self.rotation)
         T2 = Translation.from_vector(self.location)
         X = T2 * R * S * T1
     else:
         S = Scale.from_factors([self.scale] * 3)
         R = Rotation.from_euler_angles(self.rotation)
         T = Translation.from_vector(self.location)
         X = T * R * S
     mesh = self.mesh.transformed(X)
     vertex_xyz = {vertex: mesh.vertex_attributes(vertex, 'xy') + [0.0] for vertex in mesh.vertices()}
     return vertex_xyz
def test_basis_vectors():
    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
    x, y = M.basis_vectors
    assert np.allclose(x, Vector(0.41249169135312663, -0.05897071585157175, -0.9090506362335324))
    assert np.allclose(y, Vector(-0.8335562904208867, -0.4269749553355485, -0.35053715668381935))
def test_decomposed():
    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()
    assert S1 == Sc
    assert R1 == R
    assert T1 == T
Esempio n. 10
0
 def node_xyz(self):
     """dict : The view coordinates of the mesh object."""
     origin = Point(0, 0, 0)
     if self.anchor is not None:
         xyz = self.network.node_attributes(self.anchor, 'xyz')
         point = Point(*xyz)
         T1 = Translation.from_vector(origin - point)
         S = Scale.from_factors([self.scale] * 3)
         R = Rotation.from_euler_angles(self.rotation)
         T2 = Translation.from_vector(self.location)
         X = T2 * R * S * T1
     else:
         S = Scale.from_factors([self.scale] * 3)
         R = Rotation.from_euler_angles(self.rotation)
         T = Translation.from_vector(self.location)
         X = T * R * S
     network = self.network.transformed(X)
     node_xyz = {
         network: network.node_attributes(node, 'xyz')
         for node in network.nodes()
     }
     return node_xyz
Esempio n. 11
0
def test_from_euler_angles():
    ea1 = 1.4, 0.5, 2.3
    args = False, 'xyz'
    R1 = Rotation.from_euler_angles(ea1, *args)
    ea2 = R1.euler_angles(*args)
    assert allclose(ea1, ea2)

    alpha, beta, gamma = ea1
    xaxis, yaxis, zaxis = [1, 0, 0], [0, 1, 0], [0, 0, 1]
    Rx = Rotation.from_axis_and_angle(xaxis, alpha)
    Ry = Rotation.from_axis_and_angle(yaxis, beta)
    Rz = Rotation.from_axis_and_angle(zaxis, gamma)
    R2 = Rx * Ry * Rz
    assert np.allclose(R1, R2)
Esempio n. 12
0
    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
Esempio n. 13
0
    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
"""There are several ways to construct a `Rotation`.
"""
import math
from compas.geometry import Frame
from compas.geometry import Rotation

R = Rotation.from_axis_and_angle([1, 0, 0], math.radians(30))
R = Rotation.from_axis_and_angle([1, 0, 0], math.radians(30), point=[1, 0, 0])
R = Rotation.from_basis_vectors([0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
R = Rotation.from_frame(Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15]))
R = Rotation.from_axis_angle_vector([-0.043, -0.254, 0.617])
R = Rotation.from_quaternion([0.945, -0.021, -0.125, 0.303])
R = Rotation.from_euler_angles([1.4, 0.5, 2.3], static=True, axes='xyz')

print(R)
Esempio n. 15
0
def R():
    return Rotation.from_euler_angles([90, 0, 0])
Esempio n. 16
0
def test_euler_angles():
    ea1 = 1.4, 0.5, 2.3
    args = False, 'xyz'
    R1 = Rotation.from_euler_angles(ea1, *args)
    ea2 = R1.euler_angles(*args)
    assert allclose(ea1, ea2)
Esempio n. 17
0
"""Example: Rotations from euler angles, rotate an object based on 3 euler angles.
"""
from compas.geometry import Rotation

# euler angles
alpha, beta, gamma = -0.156, -0.274, 0.785
static, axes = True, 'xyz'

# Version 1: Create Rotation from angles
R1 = Rotation.from_euler_angles([alpha, beta, gamma], static, axes)

# Version 2: Concatenate 3 Rotations
xaxis, yaxis, zaxis = [1, 0, 0], [0, 1, 0], [0, 0, 1]
Rx = Rotation.from_axis_and_angle(xaxis, alpha)
Ry = Rotation.from_axis_and_angle(yaxis, beta)
Rz = Rotation.from_axis_and_angle(zaxis, gamma)

if static:  # check difference between pre- and post-concatenation!
    R2 = Rz * Ry * Rx
else:
    R2 = Rx * Ry * Rz

# Check
print(R1 == R2)