I am currently facing a more mathematical problem. I am developing an application that is interested in acceleration on the X and Y axis. In other words, I want to track the acceleration that goes left or right and forward or backward.
If the device lies on the table up, all accelerations in the desired direction are visible in the acceleration values ββof this axis. There is a problem: the device does not fit in this position and has a certain rotation around the X or Y axis (step, roll).
I need a rotation matrix (Rm), which I can multiply by the acceleration vector (x) to get a new calibrated vector (x '), other classes can work with: x' = Rm * x . This should be calculated from the reference vector (0,0, -1) and the current device gravity vector.
I know that this has something to do with Euler angles, but I cannot understand how I can calculate them and create my rotation matrix with them. I also know that the CMAttitude class has a rotation matrix, but I would like more information on how this matrix is ββcalculated.
Example:
Imagine that you want to take care of how hard you brake your bike. If your iPhone is mounted on a bicycle and the display is pointing straight up, you can read the acceleration in the y value of the acceleration vector. Other classes in your project assume that braking acceleration can always be seen in this value.
The problem is that the iPhone fits in a portrait view of a display pointing at you. Then braking does not increase the value of y, but instead the value of z. Thus, you must rotate your acceleration value by -90 degrees around the x axis.
I need this rotation matrix for arbitrary rotation of the device. I know that it is impossible to calculate the rotation around the z axis from gravity vectors, but as long as the x and y turns are denied, I'm fine.
Many thanks for your help