旋转向量转bvh旋转角度

目录

旋转向量转四元素

旋转向量转bvh旋转角度:

子节点从1  1 0 抓挠 0 1  1的例子:


答案不对

旋转向量转四元素

import numpy as np


def to_euler(x, order='zyx',face_front=False):
    
    q0 = x[...,0:1]
    q1 = x[...,1:2]
    q2 = x[...,2:3]
    q3 = x[...,3:4]
    
    if order == 'zyx':
    
        return np.concatenate([
            np.arctan2(2 * (q0 * q3 + q1 * q2), 1 - 2 * (q2 * q2 + q3 * q3)),
            np.arcsin((2 * (q0 * q2 - q3 * q1)).clip(-1,1)),
            np.arctan2(2 * (q0 * q1 + q2 * q3), 1 - 2 * (q1 * q1 + q2 * q2))], axis=-1)
            
    elif order == 'yzx':
    
        return np.concatenate([
            np.arctan2(2 * (q2 * q0 - q1 * q3),  q1 * q1 - q2 * q2 - q3 * q3 + q0 * q0),
            np.arcsin((2 * (q1 * q2 + q3 * q0)).clip(-1,1)), 
            np.arctan2(2 * (q1 * q0 - q2 * q3), -q1 * q1 + q2 * q2 - q3 * q3 + q0 * q0)],axis=-1)
            
    elif order == 'zxy':

        return np.concatenate([
            np.arctan2(2 * (q0 * q3 - q1 * q2), q0 * q0 - q1 * q1 + q2 * q2 - q3 * q3),
            np.arcsin((2 * (q0 * q1 + q2 * q3)).clip(-1,1)),
            np.arctan2(2 * (q0 * q2 - q1 * q3), q0 * q0 - q1 * q1 - q2 * q2 + q3 * q3)], axis=-1)

    elif order == 'yxz':
        
        data= np.concatenate([
            np.arctan2(2 * (q1 * q3 + q0 * q2), q0 * q0 - q1 * q1 - q2 * q2 + q3 * q3),
            np.arcsin((2 * (q0 * q1 - q2 * q3)).clip(-1,1)),
            np.arctan2(2 * (q1 * q2 + q0 * q3), q0 * q0 - q1 * q1 + q2 * q2 - q3 * q3)], axis=-1)

        data2 = from_euler(data)
        return data
        
    else:
        raise NotImplementedError('Cannot convert from ordering %s' % order)

def from_angle_axis(angle, axis):
    c = np.cos(angle / 2.0)[..., None]
    s = np.sin(angle / 2.0)[..., None]
    q = np.concatenate([c, s * axis], axis=-1)
    return q

def from_axis_angle(rots):
    angle = np.linalg.norm(rots, axis=-1)
    axis = rots / angle[..., None]
    result = np.nan_to_num(axis)
    return from_angle_axis(angle, result)

# 绕 z 轴旋转 90 度的旋转向量
rot_vector = np.array([0, 0, np.pi / 2])

# 转换为四元数
quat = from_axis_angle(rot_vector)
print(quat)

旋转向量转bvh旋转角度:

子节点从1  1 0 旋转到 0 1 1

答案是90 90 0 ,但是算出来不对。

    rots = rots_o.reshape(rots_o.shape[0], -1, 3)
    rots = quat.from_axis_angle(rots)

    positions[:, 0] = trans#*scale_v

    order = "zyx"  # rotation顺序
    # order = "zxy"  # rotation顺序
    rotations = np.degrees(quat.to_euler(rots, order=order))

子节点从1  1 0 抓挠 0 1  1的例子:

import numpy as np

def from_angle_axis(angle, axis):
    c = np.cos(angle / 2.0)[..., None]
    s = np.sin(angle / 2.0)[..., None]
    q = np.concatenate([c, s * axis], axis=-1)
    return q

def from_axis_angle(rots):
    angle = np.linalg.norm(rots, axis=-1)
    axis = rots / angle[..., None]
    result = np.nan_to_num(axis)
    return from_angle_axis(angle, result)

# 定义初始位置和目标位置
initial_position = np.array([1, 1, 0])
target_position = np.array([0, 1, 1])

# 计算旋转轴和旋转角度
rotation_axis = np.cross(initial_position, target_position)
rotation_angle = np.arccos(np.dot(initial_position, target_position) / (np.linalg.norm(initial_position) * np.linalg.norm(target_position)))

# 使用 from_axis_angle 函数计算四元数
quat = from_axis_angle(rotation_axis * rotation_angle)
print(f'四元数: {quat}')

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 可以使用软件工具进行BVH格式到BIP格式的换。例如使用Autodesk Maya软件中的"Import BVH"功能导入BVH文件,然后使用"Export Selected"功能导出为BIP格式。也可以使用其他专业的骨骼动画换软件如Houdini, MotionBuilder等。 ### 回答2: BVH是一种常用的动作捕捉数据格式,而BIP是一种专门用于3D动画软件的骨骼动画格式。因此,要将BVH格式换为BIP格式,需要进行以下步骤: 1.准备工作:首先需要准备一个3D动画软件,例如Autodesk 3ds Max或者MotionBuilder。这些软件都支持BIP格式的导入和导出。 2.导入BVH文件:使用所选的3D动画软件,导入BVH格式的文件。在导入过程中,软件会将BVH文件中的层次结构和动作数据换为相应的骨骼和动画轨迹。 3.调整骨骼:确认BVH文件成功导入后,可能需要对骨骼进行调整,以适应目标BIP格式。这可能涉及到对骨骼名称、层级结构或者骨骼的旋转角度进行修改。 4.调整关键帧:由于BVH和BIP格式之间的差异,需要对动画数据进行调整,使其适应BIP格式的要求。这包括消除非法动作或关键帧,并确保动作畅地在BIP格式的骨骼上播放。 5.导出BIP文件:完成上述调整后,通过选择导出选项,将骨骼以BIP格式导出为新的文件。在导出过程中,选择适当的选项来确保输出文件符合BIP格式规范。 总结起来,将BVH格式换为BIP格式需要导入BVH文件、调整骨骼和关键帧,并最终将其导出为BIP格式的文件。这样可以使BVH格式的动作数据能够在BIP格式的骨骼动画软件中使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法加油站

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值