How to convert a 3D acceleration into a rotation?

穿精又带淫゛_ 提交于 2019-12-06 15:38:51

Although I am working on iPhone it should basically the same problem. Your hardware needs a gyroscope sensor to describe rotations, especially those in parallel to gravity (let's call this z, x is right and y is up). If the device lays flat on the table and you rotate around this z-axis, there are only tiny accelerations measured resulting from centrifugal forces. So you can get some information about rotation, but you are limited in:

1) Users have to hold the device in specific manner for you to detect the rotation properly

2) Even if you got the best case of 45 degree to ground, it is very hard to get all 3 dimensions. You are better off, if you can limit detection on 2 rotational directions only.

3) You are limited to either rotations or translations, but combining detection of rotations with linear motions simultaneously is pretty hard.

Conclusion: For a racing game force users to hold the device in certain angle, limit on z-Rotation for steering wheel and some other direction for e.g. power slides or whatever.

Use of axis can be quite confusing. I stay with the orientation of X for horizontal axis (left and right), Y for vertical axis (up and down) and Z axis is the depth(far and near).

Using the accelerometer, you can only detect rotation about the X axis and Z axis, but not the Y axis.

Suppose your phone is place flat at rest position, the force of gravity will result in the Y acceleration to be around -9.8, and the X and Z acceleration will be around 0.

Assume that phone remains flat in the position. When you rotate the phone about the Y axis (assuming there is no translation to the phone or change in position to the phone as you rotate), there is no significant change to the value of X, Y and Z acceleration. Therefore, you can't detect any rotation about the Y axis.

When you rotate about X and Z axis (assuming no change in position of the phone while rotating), all the 3 acceleration values changes, but vectors will have the characteristic of x^2 + y^2 + z^2 = 9.8^2.

You can use simple trigonometrical formula to determine the rotation about the Z and Z axis.

As pointed out by Kay, you will still need the gyroscope to output the angular velocity of the rotation about each axis to compute the rotation about the y axis.

If you want to get the rotation angle of the phone held in your hands (ie rotated in one plane) let's say held facing your chest...

atan2(y accel., x accel.)

You'll get rotational values :) It's likely to be jittery so you'll probably want to average the results over a sample period to smooth it out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!