Compute rotation matrix using the accelerometer

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


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.


我认为以下链接应该有帮助将iPhone加速度计数据转换为汽车轴注意旋转矩阵中存在错误,元素rm11应该是cos“Beta”* cos“gamma”而不是cos“alpha”* COS“伽马”

链接地址: http://www.djcxy.com/p/81804.html

上一篇: 旋转3D立方体,使其面向用户

下一篇: 使用加速度计计算旋转矩阵