免责声明:我自己对四元数还很陌生,但在四元数附近做了一些工作。以下是我有限的知识加上一些谷歌搜索的结果。它看起来确实应该起作用。
所以听起来你要解决的问题可以表述如下:给出两个四元数(分别代表大腿和小腿的3D方向)。。。在
…计算两个四元数之间的三维角度差。。。在
。。。把角差表示为欧拉角
为了得到三维角度差,它本身就是一个四元数,你只需将一个四元数乘以另一个四元数的共轭量(reference)。在
然后需要从四元数转换为Euler角度(围绕X、Y、Z旋转)。据我所知,你需要用老式的方法,使用Wikipedia中的公式。在import pyquaternion as pyq
import math
# Create a hypothetical orientation of the upper leg and lower leg
# We use the (axis, degrees) notation because it's the most intuitive here
# Upper leg perfectly vertical with a slight rotation
q_upper = pyq.Quaternion(axis=[0.0, 0.0, -1.0], degrees=-5)
# Lower leg a little off-vertical, with a rotation in the other direction.
q_lower = pyq.Quaternion(axis=[0.1, -0.2, -0.975], degrees=10)
# Get the 3D difference between these two orientations
qd = q