I've written a JS SDK that listens to mobile device rotation, providing $3$ inputs:
$\alpha$ : An angle can range between $0$ and $360$ degrees
$\beta$ : An Angle between $-180$ and $180$ degrees
$\gamma$ : An Angle between $-90$ to $90$ degrees
I have tried using Euler Angles to determine the device orientation but encountered the gimbal lock effect, that made calculation explode when the device was pointing up. That lead me to use Quaternion, that does not suffer from the gimbal effect.
I've found a library that converts $\alpha, \beta$ and $\gamma$ to a Quaternion, so for the following values:
$\alpha : 40.3476$
$\beta : 70.3120$
$\gamma : -62.9454$
I get this Quaternion ($ZXY$ order):
Visualizing the device orientation (Demo, use mobile):
I would like to write a method that gets a Quaternion as an input and outputs if the device is on portrait or landscape mode.
Defining portrait and landscape as a range of $\pm 45^\circ$ around the relevant axes.
What approach should I take?
To elaborate further, my goals are:
To write a method that gets $\alpha, \beta$ and $\gamma$ and outputs if the device is in one of the following orientations:
- portrait upside down
- landscape left
- landscape right
- display up
- display down