【发布时间】:2020-04-21 06:06:16
【问题描述】:
在 JavaScript 中,我们可以获得设备的 alpha、beta 和 gamma 角度。
- alpha:围绕 z 轴 [0, 360] 旋转
- beta:绕 x 轴旋转 [90, -90]
- gamma:绕 y 轴旋转 [180, -180]
window.addEventListener('deviceorientation', (event)=>{
const alpha = event.alpha; // Returns the rotation of the device around the Z axis
const beta = event.beta; // Returns the rotation of the device around the X axis; that is, the number of degrees, ranged between -180 and 180
const gamma = event.gamma; // Returns the rotation of the device around the Y axis; that is, the number of degrees, ranged between -90 and 90
console.log(`alpha: ${alpha}, beta: ${beta}, gamma: ${gamma}`);
}, false);
但是,我想使用这些角度来确定设备的基本方向(北、西、东和南)。
我的问题:
是否可以只使用 alpha 角来确定设备的基本方向,还是应该同时使用 beta 和 gamma?
如果需要 beta 和 gamma;为了计算基本方向,我应该如何在计算中使用它们,有没有我应该知道的公式?
【问题讨论】:
标签: javascript