Converting world coordinates to an object

The iPhone gyro receives rotation of the data relative to a certain reference ratio and it does not change (if they do not multiply.) Suppose I face the wall using my iPhone camera and rotate it 45 degrees to the left ( roll += PI/4 ) .>

Now, if I raise the phone to the ceiling, both the yaw and the pitch change, since the fixed coordinate space (the world coordinate space does not move or rotate with the phone.) Is there a way to determine this angle (the one between the floor plane and the direction vector cameras), roll, yaw and pitch set?

Edit: instead of opening another question, I will try here. Luc solution works. But how to get two other rotation angles? I read the information about the posted link, but many years have passed since I studied linear algebra. In fact, it may be more math than a programming question.

+4
source share
1 answer

I really do not encode the iPhone, so I will trust you in the frame "real world coordinates."

In this case, you want the point-to-point between the vectors of the z axis. This will give you the cosine of the angle you are looking for, pretty close. Since the angle between the planes really makes sense as a value between and 90° , in fact you have all the necessary information in this cosine.

And there is no latex formatting, otherwise I’ll tell you a little more, but read this page , interestingly, I’ll just include the final result here, the rotation matrix for your three turns: rotation matrix

Now the horizontal axis z-axis vector is (0,0,1) (although it's like a vertical vector) and rotated with this matrix, you just get its third column.

So, we want to have a point product between this third column and our vector (0,0,1) , so you get cos(β)cos(γ) , which cos(pitch)*cos(roll)

In conclusion, the angle between your plans is arccos(cos(pitch)*cos(roll)) . This value will tell you how inclined your iPhone is, and not in which direction, of course. But you can fix it from the values ​​of the vector (the rightmost column of the matrix), which we talked about.

+2
source

Source: https://habr.com/ru/post/1444867/


All Articles