3 rotation values to work out rotation in degrees

271 Views Asked by At

I am currently working with the Oculus headset and dealing with the Z axis.

With the software I have, the values I can retrieve are limited and I was hoping someone could help me find a solution to an interesting problem of finding the degree of the headset using these values.

I have 3 values that change dependent on the degree on the z axis As I rotate the gyro within the headset positively:

Values - L, M, N

Diagram

They are true numbers when at 0,90,180 and 270 degrees. While approaching that point the increment or decrements from the previous value. (i.e at 45* it would be 0.5)

Q:Can anyone help me create a algorithm that I can add any 3 values and retrieve the degree of rotation?

Many thanks,

MC

1

There are 1 best solutions below

3
On BEST ANSWER

From the description, it seems these are not smooth functions of angle but instead are piecewise linear functions of the angle. So a formula involving atan2 or something like that is not going to work.

As a first step, I would split the algorithm into two cases:

  • when $M \geq 0$
  • when $M < 0$

In each case, you can write the angle of rotation as a linear function of $L$ alone.

The value of $N$ adds no information since you can deduce it from $M$, so you can ignore it.

This algorithm is prone to errors near $0$ degrees and $180$ degrees if the slope of $L$ does not change exactly when $M$ reaches zero. A more robust algorithm would use four cases:

  • when $M \geq 0.5$
  • when $M \leq -0.5$
  • when $-0.5 < M < 0.5$ and $L > 0$
  • when $-0.5 < M < 0.5$ and $L < 0$

The first two cases are just like the two cases before; in the last two cases, however, the angle is a linear function of $M$ alone.

This is all assuming that $L = M = 0.5$ at $45$ degrees, which I still find surprising although not impossible.

I'm sure this starts to get much more complicated very quickly if you start turning the headset in any way that is not just a rotation around the $z$ axis.