妙手镯;如何从四元数到前臂方向单位向量?

Myo bracelet; How go from quaternion to forearm direction unit vector?

我正在用 myo 手镯做一个项目。手镯使用四元数来跟踪它的方向。我想要的是一个指向我的前臂方向而没有方向的矢量,即我只想要一个代表我的前臂的单位矢量。这可能吗?有人知道怎么做吗?

我已尝试按照本网站 Maths - Transforming Vectors with Quaternions` 上的说明执行 P' = QPQ^-1 的四元数乘法,但我无法正常工作。我怀疑这是因为 Myo 手镯的四元数输出不是一次旋转,而是随着我移动 arm/the 手镯不断变化的 orientation/rotation。

基本上,我从 Myo 获得的数据是 [X,Y,Z,W] 的形式,并且随着我移动手臂而变化。如果有人愿意帮助我,我将不胜感激

干杯, // hjalle

听起来您正在尝试获取 Euler angles from the quaternion, so this reference might be a better starting point. The hello-myo example from the Myo SDK documentation (part of the SDK download here) 使用以下代码:

// Calculate Euler angles (roll, pitch, and yaw) from the unit quaternion.
float roll = atan2(2.0f * (quat.w() * quat.x() + quat.y() * quat.z()), 1.0f - 2.0f * (quat.x() * quat.x() + quat.y() * quat.y()));
float pitch = asin(max(-1.0f, min(1.0f, 2.0f * (quat.w() * quat.y() - quat.z() * quat.x()))));
float yaw = atan2(2.0f * (quat.w() * quat.z() + quat.x() * quat.y()), 1.0f - 2.0f * (quat.y() * quat.y() + quat.z() * quat.z()));

与上述内容无关,不确定它是否有帮助,但如果你想在现实世界中定位手臂,你将始终需要一个已知的参考或起始方向,然后比较所有以下测量结果。对于 Myo,这通常是通过让佩戴者将手臂放在已知位置并按下校准按钮来完成的。有时有更聪明的方法可以做到这一点,但这取决于应用程序。一旦你有了参考,你将从未来的测量中减去它以获得真正的方向,本质上:orientationReal = orientationMeasured - orientationReference 你通常希望首先以四元数格式进行此计算(参见 Gimbal lock)但取决于您的应用程序也许欧拉角就可以了。