Exemplo n.º 1
0
    def from_quaternion(cls, quaternion, point=[0, 0, 0]):
        """Construct a frame from a rotation represented by quaternion coefficients.

        Parameters
        ----------
        quaternion : list of float
            Four numbers that represent the four coefficient values of a quaternion.
        point : list of float, optional
            The point of the frame.
            Defaults to [0, 0, 0].

        Returns
        -------
        :class:`compas.geometry.Frame`
            The constructed frame.

        Examples
        --------
        >>> q1 = [0.945, -0.021, -0.125, 0.303]
        >>> f = Frame.from_quaternion(q1, point=[1., 1., 1.])
        >>> q2 = f.quaternion
        >>> allclose(q1, q2, tol=1e-03)
        True
        """
        R = matrix_from_quaternion(quaternion)
        xaxis, yaxis = basis_vectors_from_matrix(R)
        return cls(point, xaxis, yaxis)
Exemplo n.º 2
0
def test_matrix_from_quaternion():
    q1 = [0.945, -0.021, -0.125, 0.303]
    R = matrix_from_quaternion(q1)
    r = [[0.7853252073134178, -0.5669097811969227, -0.2487521230892197, 0.0],
         [0.5774003396942752, 0.8156659006893796, -0.0360275751823359, 0.0],
         [0.22332300929163754, -0.11533619742231993, 0.9678968927964832, 0.0],
         [0.0, 0.0, 0.0, 1.0]]
    assert allclose(R, r)
Exemplo n.º 3
0
 def get_matrix_from_trs(self, node):
     matrix = identity_matrix(4)
     if 'translation' in node:
         translation = matrix_from_translation(node['translation'])
         matrix = multiply_matrices(matrix, translation)
     if 'rotation' in node:
         rotation = matrix_from_quaternion(node['rotation'])
         matrix = multiply_matrices(matrix, rotation)
     if 'scale' in node:
         scale = matrix_from_scale_factors(node['scale'])
         matrix = multiply_matrices(matrix, scale)
     return matrix
Exemplo n.º 4
0
    def get_matrix_from_trs(self):
        """If the node's displacement from the origin is given by its translation, rotation and
        scale attributes, this method returns the matrix given by the composition of these
        attributes.

        Returns
        -------

        """
        matrix = identity_matrix(4)
        if self.translation:
            translation = matrix_from_translation(self.translation)
            matrix = multiply_matrices(matrix, translation)
        if self.rotation:
            rotation = matrix_from_quaternion(self.rotation)
            matrix = multiply_matrices(matrix, rotation)
        if self.scale:
            scale = matrix_from_scale_factors(self.scale)
            matrix = multiply_matrices(matrix, scale)
        return matrix
Exemplo n.º 5
0
def test_quaternion_from_matrix():
    q1 = [0.945, -0.021, -0.125, 0.303]
    R = matrix_from_quaternion(q1)
    q2 = quaternion_from_matrix(R)
    assert allclose(q1, q2, tol=1e-03)