I\'m trying to use this library at https://docs.microsoft.com/en-us/xamarin/essentials/orientation-sensor to work out the devices pitch, yaw, and roll. The library works, and r
According to the document:
A Quaternion value is very closely related to rotation around an axis. If an axis of rotation is the normalized vector (ax, ay, az), and the rotation angle is Θ, then the (X, Y, Z, W) components of the quaternion are:
(ax·sin(Θ/2), ay·sin(Θ/2), az·sin(Θ/2), cos(Θ/2))
First, get Θ
from W
:
var Θ = Math.Acos(W)*2;
Then, get ax
,ay
,az
by:
var ax = X / Math.Sin(Math.Acos(Θ));
var ay = Y / Math.Sin(Math.Acos(Θ));
var az = Z / Math.Sin(Math.Acos(Θ));
The Axis Angle of the Quaternion is [ax, ay, az].
For example, a Quaternion
of [0,0,0.7071068,0.7071068]
will have an Axis-Angle
of [0,0,1]
. You could consider it rotated 90 degrees on the Z axis.