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 : list of float Three numbers that represent the axis of rotation and angle of rotation by its magnitude. point : list of float, optional The point of the frame. Defaults to [0, 0, 0]. Returns ------- :class:`compas.geometry.Frame` The constructed frame. Examples -------- >>> 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_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)
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_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 allclose( xaxis, [0.6807833515407016, 0.6807833515407016, 0.2703110366411609]) assert allclose( yaxis, [-0.6687681911461376, 0.7282315441900513, -0.14975955581430114])