javascript - 如何获得相对于另一个原点的四元数旋转
问题描述
我正在尝试基于返回四元数的 RelativeOrientationSensor 映射智能手机方向。
目前,我正在执行以下操作:
- 捕获参考四元数(传感器报告的第一个),我想将其视为新的原点。
- 使用以下方法将旋转中的每个方向差异保存到参考四元数:
diff.name = portrait
diff.quaternion = currentQuaternion.multiply(referenceQuaternion.inverse())
- 将旋转差异与保存的每个差异进行比较以了解当前方向
orientation = diffs.min(diff => distanceToIdentity(currentQuaternion.multiply(diff.quaternion.inverse()))
我计算身份距离的方式是sum of the x, y, z components + the absolute distance between the w component and 1.
但是我这样做的方式是不正确的,因为当我更改初始四元数并复制方向变化时差异不是恒定的