sqrt((x*x)+(y*y)) calculates the length of the hypotenuse of a right triangle with sides X and Y (Pythagorean Theorem)

Unfortunately it gives the absolute magnitude and destroys information about quadrant. I guess you need the sign information for the various forces to determine pitch and roll correctly.

Yes John.

I am gonna try and use the signs, but even the magnitude does not make sense because we get 45 degrees instead of 90.

I figured out the problem with my earlier code, the first one 1 posted.

What happens there is this

For xrot(roll) i use the y-z plane to get the angle, and for yrot(pitch) i use the x-z plane to get the angle. This is perfectly fine if i just want to calculate either the roll alone or the pitch alone.

I hold the device on my palm with my palm facing upwards, such that z points upwards and the x along my fingers.

Now if i do roll then I am right in measuring the angle in the y-z plane. And if I do pitch, then I am right in measuring the angle in the x-z plane.

Which works fine for both.

But now if i do a roll by +90 degrees, (counterclockwise), then and now if I want to do a pitch, then the pitching plane has changed, it has now become x-y plane instead of the x-z plane.

So i cannot get pitch and roll simultaneously.

I am stuck!!