Core Motion - Convert local euler angles to another reference system
I got a problem with the maths involved in converting local Euler angles into the angles of another reference system. Lets say we have an iPhone aligned with the axis of an vehicle and I want to measure the roll angle, then the roll angle of the iPhone equals the roll angle of the device. But what if the iPhone is mounted tilt. In this开发者_如何学Python case I would have to convert the local Euler angles to another reference frame (e.g. the cars). Could someone please point me in the right direction?
I assume you want to know the roll of the car, rather than the phone. The phone needs to known the initial reference frame. So, suppose you line up the phone with the car at the start. Then press a button on the phone. At that button press, in your code store the attitude that you get from CMDeviceMotion.
If you want to know the roll of the car at any point after that, take the current attitude from CMDeviceMotion. Then call multiplyByInverseOfAttitude:
on it, supplying the initial reference frame as parameter. That will give you the difference between the initial reference frame and the current one.
If you take the roll property from that, it should be the roll angle of the car.
精彩评论