当设备旋转一定的量时,一个简单的立方体必须旋转相同的量,但方向相反。例如,如果设备向右旋转45度,则立方体必须向左旋转45度。或者当间距为30度时,立方体必须绕X轴旋转-30度。当偏航为10度时,立方体必须绕Z轴旋转-10度。我先使用.getRotationMatrixFromVector,然后使用getOrientation,如下所示:
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
SensorManager.getRotationMatrixFromVector(
mRotationMatrix , event.values);
SensorManager.getOrientation(mRotationMatrix, orientationVals);
azimuthVal = (Math.round((Math.toDegrees(orientationVals[0]))*100.0)/100.0);
pitchVal= (Math.round((Math.toDegrees(orientationVals[1]))*100.0)/100.0);
rollVal = (Math.round((Math.toDegrees(orientationVals[2]))*100.0)/100.0);}但是它的问题是,螺距的变化会影响滚动,反之亦然,因此当设备绕X轴旋转时,夹紧值发生变化-> roll ->立方体不仅围绕X旋转,而且还围绕Y旋转,当我不需要它的时候。
我在互联网上四处寻找,许多人将四元数作为解决方案,但我如何将四元数应用到我的特定应用程序中,因为我需要知道设备沿轴线旋转的度数。
发布于 2015-09-23 17:45:39
当你想要从旋转矩阵中提取(Euler)旋转角时,就会发生万向锁定,基本上在某些特定的旋转中,我们在旋转矩阵分量和旋转角之间的方程中失去了一个自由度,并且实际的旋转角是不可恢复的,
所以在你的代码中,它可能发生在: SensorManager.getOrientation(mRotationMatrix,orientationVals);
在提取旋转角度之前,您应该以某种方式解决这个问题,这可以通过修改四元数的组件来完成,如下所述:
http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/
https://stackoverflow.com/questions/15345944
复制相似问题