def from_matrix(cls, matrix): """Construct a frame from a matrix. Parameters ---------- matrix : list of list of float The 4x4 transformation matrix in row-major order. Returns ------- :class:`compas.geometry.Frame` The constructed frame. Examples -------- >>> 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 """ _, _, angles, point, _ = decompose_matrix(matrix) R = matrix_from_euler_angles(angles, static=True, axes='xyz') xaxis, yaxis = basis_vectors_from_matrix(R) return cls(point, xaxis, 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 : list of float Three numbers that represent the angles of rotations about the defined axes. static : bool, optional If true the rotations are applied to a static frame. If not, to a rotational. Defaults to true. axes : str, optional A 3 character string specifying the order of the axes. Defaults to 'xyz'. point : list of float, optional The point of the frame. Defaults to ``[0, 0, 0]``. Returns ------- :class:`compas.geometry.Frame` The constructed frame. Examples -------- >>> 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 test_matrix_from_euler_angles(): ea1 = 1.4, 0.5, 2.3 args = True, 'xyz' R = matrix_from_euler_angles(ea1, *args) r = [[-0.5847122176808724, -0.4415273357486694, 0.6805624396639868, 0.0], [0.6544178905170501, 0.23906322244658262, 0.7173464994301357, 0.0], [-0.479425538604203, 0.8648134986574489, 0.14916020070358058, 0.0], [0.0, 0.0, 0.0, 1.0]] assert allclose(R, r)
def test_euler_angles_from_matrix(): ea1 = 1.4, 0.5, 2.3 args = True, 'xyz' R = matrix_from_euler_angles(ea1, *args) ea2 = euler_angles_from_matrix(R, *args) assert allclose(ea1, ea2)