4
votes

The iPhone gyroscope receives rotation data relative to some reference attitude and it doesn't change (unless multiplied.) Lets say I face the wall using my iPhone camera, and rotate 45 degrees left (roll += PI/4.)

Now, if I lift the phone towards the ceiling, both yaw and pitch change since the coordinate space is fixed (world coordinate space, doesn't move or rotate with the phone.) Is there a way to determine this angle (the one between the floor plane and the camera direction vector), roll, yaw and pitch given?

Edit: Instead of opening another question I'll try here. Luc's solution works. But how to get the other two angles of rotation? I've read the info on the posted link but it's been years since I studied linear algebra. This might be more math than a programming question, actually.

1
That doesn't sound correct. Those little gyros measure rotation rate about an axis fixed to the phone (not to the earth). Not sure if they process that and provide an API for some higher level data.phkahler
That's what I initially thought. I rotated the phone 90 degrees up, so it points to the ceiling and the pitch was changing. Went back, rotated to the left by 90 degrees and rotated toward the ceiling, and the yaw was changing instead of pitch.Mercurial
I want to determine the angle between the floor plane and the phone at any point in real time. I only need the vertical angle, since I'm drawing some stuff on the screen using openGL and their positions are based on the vertical angle of the phone, the one between the floor plane and the phone camera vector.Mercurial

1 Answers

2
votes

I don't really code for iPhone so I'll trust you on the "real world coordinates" frame.

In that case, you want the dot product between both z-axis' vectors. That'll give you the cosine of the angle you're looking for, pretty close thus. Since an angle between planes only really makes sense as a value between and 90°, you actually have all the information you need in that cosine.

And there is no latex formatting here, otherwise I'd go into a bit more of detail, but read this page if you're interested, I'll just include the final result here, the rotation matrix for your three rotations : rotation matrix

Now the z-axis' vector of the horizontal plan is (0,0,1) (read this as a vertical vector though) and rotated with this matrix, you simply get its third column.

So we want to have the dot product between that third column and our (0,0,1) vector, so you get cos(β)cos(γ) which is cos(pitch)*cos(roll)

In conclusion, the angle between your plans is arccos(cos(pitch)*cos(roll)). This value will tell you how much your iPhone is inclined, not in which direction of course. But you can work that out from the values of the vector (rightmost column of the matrix) we spoke of.