def from_axis_angle_vector(cls, axis_angle_vector, point=[0, 0, 0]): """Construct a frame from an axis-angle vector representing the rotation. Parameters ---------- axis_angle_vector : :obj:`list` of :obj:`float` Three numbers that represent the axis of rotation and angle of rotation by its magnitude. point : :obj:`list` of :obj:`float`, optional The point of the frame. Defaults to [0, 0, 0]. Returns ------- Frame The constructed frame. Examples -------- >>> from compas.geometry import Frame >>> aav1 = [-0.043, -0.254, 0.617] >>> f = Frame.from_axis_angle_vector(aav1, point = [0, 0, 0]) >>> aav2 = f.axis_angle_vector >>> allclose(aav1, aav2) True """ R = matrix_from_axis_angle_vector(axis_angle_vector) xaxis, yaxis = basis_vectors_from_matrix(R) return cls(point, xaxis, yaxis)
def from_matrix(cls, matrix): """Construct a frame from a matrix. Parameters ---------- matrix : :obj:`list` of :obj:`list` of :obj:`float` The 4x4 transformation matrix in row-major order. Returns ------- Frame The constructed frame. Examples -------- >>> from compas.geometry import Frame >>> from compas.geometry import matrix_from_euler_angles >>> ea1 = [0.5, 0.4, 0.8] >>> M = matrix_from_euler_angles(ea1) >>> f = Frame.from_matrix(M) >>> ea2 = f.euler_angles() >>> allclose(ea1, ea2) True """ sc, sh, a, point, p = decompose_matrix(matrix) R = matrix_from_euler_angles(a, static=True, axes='xyz') xaxis, yaxis = basis_vectors_from_matrix(R) return cls(point, xaxis, yaxis)
def from_quaternion(cls, quaternion, point=[0, 0, 0]): """Construct a frame from a rotation represented by quaternion coefficients. Parameters ---------- quaternion : :obj:`list` of :obj:`float` Four numbers that represent the four coefficient values of a quaternion. point : :obj:`list` of :obj:`float`, optional The point of the frame. Defaults to [0, 0, 0]. Returns ------- Frame The constructed frame. Examples -------- >>> from compas.geometry import Frame >>> 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)
def test_basis_vectors_from_matrix(): f = Frame([0, 0, 0], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15]) R = matrix_from_frame(f) xaxis, yaxis = basis_vectors_from_matrix(R) assert np.allclose( xaxis, [0.6807833515407016, 0.6807833515407016, 0.2703110366411609]) assert np.allclose( yaxis, [-0.6687681911461376, 0.7282315441900513, -0.14975955581430114])
def basis_vectors(self): """Returns the basis vectors from the ``Rotation`` component of the ``Transformation``. """ sc, sh, a, t, p = decompose_matrix(self.matrix) R = matrix_from_euler_angles(a, static=True, axes='xyz') xv, yv = basis_vectors_from_matrix(R) return Vector(*xv), Vector(*yv)
def basis_vectors(self): """Returns the basis vectors from the ``Rotation`` component of the ``Transformation``. """ # this has to be here to avoid circular import from compas.geometry.primitives import Vector sc, sh, a, t, p = decompose_matrix(self.matrix) R = matrix_from_euler_angles(a, static=True, axes='xyz') xv, yv = basis_vectors_from_matrix(R) return Vector(*xv), Vector(*yv)
def basis_vectors(self): """The basis vectors from the rotation component of the transformation matrix. Returns ------- tuple of :class:`compas.geometry.Vector` The basis vectors of the rotation component of the tranformation. """ from compas.geometry import Vector x, y = basis_vectors_from_matrix(self.rotation.matrix) return Vector(*x), Vector(*y)
def basis_vectors(self): """Returns the basis vectors of the ``Rotation``. Returns ------- tuple of (:class:`Vector`, :class:`Vector`) The basis vectors. """ from compas.geometry import Vector xaxis, yaxis = basis_vectors_from_matrix(self.matrix) return Vector(*xaxis), Vector(*yaxis)
def from_euler_angles(cls, euler_angles, static=True, axes='xyz', point=[0, 0, 0]): """Construct a frame from a rotation represented by Euler angles. Parameters ---------- euler_angles : :obj:`list` of :obj:`float` Three numbers that represent the angles of rotations about the defined axes. static : :obj:`bool`, optional If true the rotations are applied to a static frame. If not, to a rotational. Defaults to true. axes : :obj:`str`, optional A 3 character string specifying the order of the axes. Defaults to 'xyz'. point : :obj:`list` of :obj:`float`, optional The point of the frame. Defaults to [0, 0, 0]. Returns ------- Frame The constructed frame. Examples -------- >>> from compas.geometry import Frame >>> ea1 = 1.4, 0.5, 2.3 >>> f = Frame.from_euler_angles(ea1, static = True, axes = 'xyz') >>> ea2 = f.euler_angles(static = True, axes = 'xyz') >>> allclose(ea1, ea2) True """ R = matrix_from_euler_angles(euler_angles, static, axes) xaxis, yaxis = basis_vectors_from_matrix(R) return cls(point, xaxis, yaxis)
def basis_vectors(self): """Returns the basis vectors of the ``Rotation``. """ return basis_vectors_from_matrix(self.matrix)
def basis_vectors(self): from compas.geometry import Vector xaxis, yaxis = basis_vectors_from_matrix(self.matrix) return Vector(*xaxis), Vector(*yaxis)
def basis_vectors(self): from compas.geometry import Vector x, y = basis_vectors_from_matrix(self.rotation.matrix) return Vector(*x), Vector(*y)