views:

63

answers:

2

Is there a formula to convert a quaternion to an angle?

Looking to do something on the iPhone using the Core Motion API and the gyro so that based on data I receive from it (in the form of quaternions) I can project a UIView on the screen.

Thanks

+1  A: 

Yes, see Quaternions and spatial rotation. The unit quaternion (w, x, y, z) represents a rotation about the axis (x, y, z) of an angle of 2*cos-1(w).

Note that this is only true of unit quaternions. Non-unit quaternions do not represent rotations.

Adam Rosenfield
Is this going to give me both the horizontal and vertical angles? Again, I'm working with an iPhone 4 and try to project a UIView on to the screen based on how the phone is being held. thanks
wgpubs
A: 

You want the angle between a quaternion and what?

A quaternion is like a vector in 4D space.

You can find a angle between two quaternions.

pablosaraiva
The reference point would be (0,0,0) in terms of an x,y,z coordinate I suppose.
wgpubs
Ok, (0,0,0) is a point. But, thinking 3D space, the vector is pointing where?
pablosaraiva
Magnetic north for my purposes
wgpubs
Then you'll have to calculate that quaternion too, because it depends on the mobile phone position. I'll look for some method for calculating the angle between two quaternions then post here.
pablosaraiva
Cool thanks. Much appreciated!
wgpubs