I'm working on a cross-platform augmented-reality library, my Android code works great, but I'm having trouble with iOS. I'm using Android's TYPE_ROTATION_VECTOR sensor, which produces a SensorEvent. This event returns an array of 5 values (as described here), which are used to generate a rotation matrix (using this method). I'm only really interested in the first 4 values. They're described as:
SensorEvent.values[0] x *sin(θ/2)
SensorEvent.values[1] y *sin(θ/2)
SensorEvent.values[2] z *sin(θ/2)
SensorEvent.values[3] cos(θ/2)
The aforementioned link goes on to say
The rotation-vector sensor (TYPE_ROTATION_VECTOR) provides the orientation of the device with respect to Earth's coordinate system as a unit quaternion. Specifically, the rotation vector represents the orientation of the device as a combination of an angle and an axis, in which the device has rotated through an angle θ around an axis < x , y , z >. The first four elements of the rotation vector are equal to the components of a unit quaternion x sin(θ/2), y sin(θ/2), z *sin(θ/2)>. The elements of the rotation vector are unitless.
CoreMotion in iOS provides a quaternion reading, but it doesn't seem to correlate to Android's TYPE_ROTATION_VECTOR values (at least not directly). I've also tried deviceMotion's attitude.rotationMatrix value directly, but it's not useful.
So my question is: in iOS, how can I obtain sensor values equivalent to Android's TYPE_ROTATION_VECTOR?