Every content here is my original work.Creative Commons Licence
Universitas Scripta is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Your cookies may be used by Google and mathjax. See Google's privacy policy.

Saturday 3 July 2021

One old Apple's bug and its remedy.

*The problem I am going to explain now has been always there as far as I know. Thus, I don't know whether this problem appeared some day, or has been there since its beginning, or has been fixed very recently while I haven't noticed. However, I highly suspect that the problem is still there from the beginning to now, and no one seems to be interested in addressing or fixing this issue while it is very annoying problem in practical use.


In Apple's API, Gyro data is represented in CMAttitude 3D Euler angle object, and this has 2 different representations, rotation matrix and quaternion. Mathematics proves that there shall be 2 singularities, north and south pole. Due to Apple's weird coordinate definition (Getting Raw Gyroscope Events | Apple Developer Documentation), those singularities happens at very annoying position: as far as I remember, it is upright position. Anyway, I remember that the position was in very frequent daily use area.


Now, when you want to measure relative rotation, you may use 

or

but any of these move singularities. I think this seems that Apple internally performs operation between two CMAttitude object by converting into quaternions and multiplying them. As the conversion to quaternion is not a one-to-one function, quaternion operations seems not to move singularities.


If you replace CMAttitude.multiply(byInverseOf: CMAttitude) to explicit CMMatrix multiplication, you can confirm that the singularities move to the farthest points from the reference attitude.