已知 [x,y,z,rx,ry,rz ] 求 RT矩阵 ,给出 python 代码 rx ry rz 是 欧拉角 xyz 使用 numpy

部署运行你感兴趣的模型镜像


import numpy as np

def euler_xyz_to_rotation_matrix(rx, ry, rz, degrees=False):
    """
    手动计算 XYZ 欧拉角到旋转矩阵的转换
    
    Args:
        rx, ry, rz: 绕X、Y、Z轴的旋转角度
        degrees: 如果为True,输入角度为度数;如果为False,输入为弧度
    
    Returns:
        3x3 旋转矩阵
    """
    if degrees:
        rx, ry, rz = np.radians(rx), np.radians(ry), np.radians(rz)
    
    # 绕X轴旋转的矩阵
    Rx = np.array([
        [1, 0, 0],
        [0, np.cos(rx), -np.sin(rx)],
        [0, np.sin(rx), np.cos(rx)]
    ])
    
    # 绕Y轴旋转的矩阵
    Ry = np.array([
        [np.cos(ry), 0, np.sin(ry)],
        [0, 1, 0],
        [-np.sin(ry), 0, np.cos(ry)]
    ])
    
    # 绕Z轴旋转的矩阵
    Rz = np.array([
        [np.cos(rz), -np.sin(rz), 0],
        [np.sin(rz), np.cos(rz), 0],
        [0, 0, 1]
    ])
    
    # XYZ顺序:先X,再Y,最后Z (R = Rz * Ry * Rx)
    rotation_matrix = Rz @ Ry @ Rx
    
    return rotation_matrix

def manual_euler_xyz_to_rt_matrix(pose, degrees=False):
    """
    手动实现 XYZ 欧拉角到 RT 矩阵的转换
    """
    # 提取平移部分
    translation = np.array(pose[:3])
    
    # 提取欧拉角
    rx, ry, rz = pose[3:]
    
    # 计算旋转矩阵
    rotation_matrix = euler_xyz_to_rotation_matrix(rx, ry, rz, degrees)
    
    # 构建 4x4 RT 矩阵
    rt_matrix = np.eye(4)
    rt_matrix[:3, :3] = rotation_matrix
    rt_matrix[:3, 3] = translation
    
    return rt_matrix

# 示例使用
pose = [1.0, 2.0, 3.0, 0.1, 0.2, 0.3]  # 弧度
rt_matrix = manual_euler_xyz_to_rt_matrix(pose, degrees=False)
print("手动计算的 RT 矩阵 (XYZ欧拉角):")
print(rt_matrix)
手动计算的 RT 矩阵 (XYZ欧拉角):
[[ 0.93629336 -0.27509585  0.21835066  1.        ]
 [ 0.28962948  0.95642509 -0.03695701  2.        ]
 [-0.19866933  0.0978434   0.97517033  3.        ]
 [ 0.          0.          0.          1.        ]]

您可能感兴趣的与本文相关的镜像

Python3.9

Python3.9

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值