Reputation: 73721
I am using the Rotation Vector
sensor to try to track how many degrees rotation 0-360 around the X
axis (aka wrist movement) the user moves.
I am using the SensorManagers
getOrientation to the the yaw, pitch and roll this way
float[] rotationMatrix = new float[9];
SensorManager.getRotationMatrixFromVector(rotationMatrix, sensorData.getValues());
float[] orientation = new float[3];
SensorManager.getOrientation(rotationMatrix, orientation);
with the watch face pointing up it gives 0 degrees like I want but when I rotate I only get +/- 90 degree increments. rotating left gives me +90 degrees and rotating right gives me -90 degrees. I i continue rotating lets say from the +90 degrees I start getting negative degrees so when the watch is face down (180 degrees) is shows 0
again. using 90 degree increments is going to make it difficult to accurately get the actual rotation angle.
Is there a way to go from +/- 90 degree increments to 0-360 degrees?
Upvotes: 2
Views: 794
Reputation: 430
You can use the z
rotation value to find out whether the watch is face up or down. This determines the perspective you are viewing from and gives you 4 quadrants, instead of the 2 that you started with.
If z
is positive: watch is face up. If z
is negative, it is face down.
From here, you can create a coordinate system for conversion.
If the watch is facing up, coordinate is 90+x_rotation
. Since rotating right gives [-90,0), and rotating left yields [0,90], this gives degrees of [-90+90,90+90] = [0, 180]
Which is what we would expect of a watch facing up on the wrist.
If the watch is facing down, coordinate is 270+x_rotation
. Quadrant 3 gives negative values of 90, making the values range from [270+-90,270] = [180,270]
. Likewise, Quadrant 4 has positive values of 90, creating a range of [270,90+270]
. So a watch facing down gives [180, 360]
.
Combined, we get the complete [0,360]
device rotation range.
Hope this helps!
Upvotes: 1