In JavaScript we can get a device alpha, beta and gamma angles.
- alpha: rotation around the z-axis [0, 360]
- beta: rotation around the x-axis [90, -90]
- gamma: rotation around the y-axis [180, -180]
(source: google.com)
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);
However, I want use these angles to determine the device cardinal direction (North, West, East and South).
My question:
Is it possible to just use the alpha-angle to determine the cardinal direction of the device, or should I also use beta and gamma?
If beta and gamma are needed; in order to calculate the cardinal direction, how should I use them in my calculation, is there any formulas I should know of?