4

I'm currently facing a more mathematical problem. I'm developing an application which is interested in acceleration in X and Y axis. In other words I want to track acceleration which goes left or right and forth or back.

If the device is lying on a table facing up all accelerations in the needed direction are visible in the acceleration values of these axis. A problem occurs is the device not placed in such a position and has a certain rotation around the X or Y axis (pitch, roll).

I need a rotation matrix (Rm) that I can multiply to a measures acceleration (x) vector to gain a new calibrated vector (x') other classes can work with: x' = Rm * x. This should be calculated out of the reference vector (0,0,-1) and the current gravity vector of the device.

I know it has something to do with Euler angles but I can not figure out how I can calculate those and create my rotation matrix with these. I also know that there is a rotation matrix in the CMAttitude class but I would like to have more insight in how these matrix is computed.

Example:

Imagine you want to messure how hard you a braking on your bike. If your iPhone is mounted on the bike with the display pointing straight up you can read the acceleration in the y value of the acceleration vector. Other classes in your project assume that the acceleration when braking can always be seen in this value.

The problem is when the iPhone is placed in portrait view the display pointing to you. Then braking would not increase the y value but the z value instead. So you have to rotate your acceleration value for -90 degree around the x axis.

I need this rotation matrix for arbitrary rotation of the device. I know that it is not possible to calculate the rotation around the z axis from gravity vectors but as long x and y rotations are negated I'm fine.

Thanks a lot for your help

ChrisIsBack
  • 225
  • 4
  • 12
  • I would suggest you to retag this question for opening it up to a broader audience. This is not really an iPhone limited issue but perfectly well answerable also by Android coders for example. – Till Dec 09 '11 at 21:10

2 Answers2

1

i think that the following link it should be helpful Transforming iPhone Accelerometer Data to Automobile Axes pay attention there is a error in the rotation matrix, the element rm11 it should be cos"Beta"*cos"gamma" and not cos"alpha"*cos"gamma"

Batti
  • 425
  • 4
  • 15
  • Batti, the page you linked to is password protected. Do you have access to it and can post elsewhere? – t9mike Aug 12 '12 at 22:30
  • Never mind. [DeviceMotion relative to world - multiplyByInverseOfAttitude](http://stackoverflow.com/a/8006783/420175) shows how to transform device-relative acceleration values to earth-relative for iOS5 and above. – t9mike Aug 13 '12 at 00:48
0

To calculate the Euler angle you need to compute the angle between the reference vector and the current gravity vector.

http://chemistry.about.com/od/workedchemistryproblems/a/scalar-product-vectors-problem.htm

The rotation matrix is pretty easy after that. http://en.wikipedia.org/wiki/Rotation_matrix

Note I am sure there are plenty of easy ways to do this within ios and android without having to make these calculations manually. This answer is just how the geometry works out.

Pablitorun
  • 1,035
  • 1
  • 8
  • 18
  • Thanks for you answer. I need to negate the rotation around the x and y axis so that all acceleration (left,right,back,front) shows up in the x and y values of the acceleration vector and is not contained in the z value. So I need an angle for the x rotation and an angle for the y rotation and combine both to an rotation matrix. I don't see how I can achieve these with just the angle between those vectors. How would the rotation matrix look like? – ChrisIsBack Dec 09 '11 at 21:59
  • can you describe a little more what you are trying to do? Big picture I mean. – Pablitorun Dec 09 '11 at 22:24
  • I'm not allowed to post any pictures – ChrisIsBack Dec 10 '11 at 00:07