Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

import numpy as np import pandas as pd def quaterniontoeuler(q): w, x, y, z = q…

  1. User

    import numpy as np import pandas as pd

    def quaternion_to_euler(q): w, x, y, z = q

    计算滚转角(roll)

    sinr_cosp = 2.0 * (w * x + y * z)
    cosr_cosp = 1.0 - 2.0 * (x * x + y * y)
    roll = np.arctan2(sinr_cosp, cosr_cosp)
    

    计算俯仰角(pitch)

    sinp = 2.0 * (w * y - z * x)
    if np.abs(sinp) >= 1:
        pitch = np.sign(sinp) * np.pi / 2
    else:
        pitch = np.arcsin(sinp)
    

    计算偏航角(yaw)

    siny_cosp = 2.0 * (w * z + x * y)
    cosy_cosp = 1.0 - 2.0 * (y * y + z * z)
    yaw = np.arctan2(siny_cosp, cosy_cosp)
    
    return np.degrees(roll), np.degrees(pitch), np.degrees(yaw)
    

    从 Excel 中读取数据

    data = pd.read_csv('F:\potree\ceshi\py\pano-poses.csv')

    提取数据列

    w_values = data[' pano_ori_w'] x_values = data[' pano_ori_x'] y_values = data[' pano_ori_y'] z_values = data[' pano_ori_z']

    逐个计算欧拉角

    euler_angles = [] for i in range(len(w_values)): q = [w_values[i], x_values[i], y_values[i], z_values[i]] euler_angle = quaternion_to_euler(q) euler_angles.append(euler_angle)

    显示结果

    for i in range(len(euler_angles)): print("Quaternion {}: Roll: {:.8f}, Pitch: {:.8f}, Yaw: {:.8f}".format(i+1, euler_angles[i][0], euler_angles[i][1], euler_angles[i][2] ))print的结果存储到.csv文件中

  2. Assistant

    import numpy as np import pandas as pd

    def quaternion_to_euler(q): w, x, y, z = q

    # 计算滚转角(roll)
    sinr_cosp = 2.0 * (w * x + y * z)
    cosr_cosp = 1.0 - 2.0 * (x * x + y * y)
    roll = np.arctan2(sinr_cosp, cosr_cosp)
    
    # 计算俯仰角(pitch)
    sinp = 2.0 * (w * y - z * x)
    if np.abs(sinp) >= 1:
        pitch = np.sign(sinp) * np.pi / 2
    else:
        pitch = np.arcsin(sinp)
    
    # 计算偏航角(yaw)
    siny_cosp = 2.0 * (w * z + x * y)
    cosy_cosp = 1.0 - 2.0 * (y * y + z * z)
    yaw = np.arctan2(siny_cosp, cosy_cosp)
    
    return np.degrees(roll), np.degrees(pitch), np.degrees(yaw)
    

    从 Excel 中读取数据

    data = pd.read_csv('F:\potree\ceshi\py\pano-poses.csv')

    提取数据列

    w_values = data[' pano_ori_w'] x_values = data[' pano_ori_x'] y_values = data[' pano_ori_y'] z_values = data[' pano_ori_z']

    逐个计算欧拉角

    euler_angles = [] for i in range(len(w_values)): q = [w_values[i], x_values[i], y_values[i], z_values[i]] euler_angle = quaternion_to_euler(q) euler_angles.append(euler_angle)

    保存结果到CSV文件

    result = pd.DataFrame({'Quaternion': range(1, len(euler_angles)+1), 'Roll': [euler_angle[0] for euler_angle in euler_angles], 'Pitch': [euler_angle[1] for euler_angle in euler_angles], 'Yaw': [euler_angle[2] for euler_angle in euler_angles]}) result.to_csv('F:\potree\ceshi\py\euler-angles.csv', index=False)

    print("Euler angles saved to euler-angles.csv")

  3. User

    输出的结果转化为下面的TXT文件

  4. Assistant

    import numpy as np import pandas as pd

    def quaternion_to_euler(q): w, x, y, z = q

    # 计算滚转角(roll)
    sinr_cosp = 2.0 * (w * x + y * z)
    cosr_cosp = 1.0 - 2.0 * (x * x + y * y)
    roll = np.arctan2(sinr_cosp, cosr_cosp)
    
    # 计算俯仰角(pitch)
    sinp = 2.0 * (w * y - z * x)
    if np.abs(sinp) >= 1:
        pitch = np.sign(sinp) * np.pi / 2
    else:
        pitch = np.arcsin(sinp)
    
    # 计算偏航角(yaw)
    siny_cosp = 2.0 * (w * z + x * y)
    cosy_cosp = 1.0 - 2.0 * (y * y + z * z)
    yaw = np.arctan2(siny_cosp, cosy_cosp)
    
    return np.degrees(roll), np.degrees(pitch), np.degrees(yaw)
    

    从 Excel 中读取数据

    data = pd.read_csv('F:\potree\ceshi\py\pano-poses.csv')

    提取数据列

    w_values = data[' pano_ori_w'] x_values = data[' pano_ori_x'] y_values = data[' pano_ori_y'] z_values = data[' pano_ori_z']

    逐个计算欧拉角

    euler_angles = [] for i in range(len(w_values)): q = [w_values[i], x_values[i], y_values[i], z_values[i]] euler_angle = quaternion_to_euler(q) euler_angles.append(euler_angle)

    保存结果到TXT文件

    with open('F:\potree\ceshi\py\euler-angles.txt', 'w') as f: for i in range(len(euler_angles)): f.write("Quaternion {}: Roll: {:.8f}, Pitch: {:.8f}, Yaw: {:.8f}\n".format(i+1, euler_angles[i][0], euler_angles[i][1], euler_angles[i][2]))

    print("Euler angles saved to euler-angles.txt")