Answer the question
In order to leave comments, you need to log in
How to get the rotation angle in degrees?
How to learn the angle of rotation in degrees? Connected accelerometer and magnetic field sensor. Each sensor gives 3 values.
float[] valuesAccel = new float[3];
float[] valuesMagnet = new float[3];
float[] valuesAccelGravity = new float[3];
public void onSensorChanged(SensorEvent event) {
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
for (int i = 0; i < 3; i++) {
valuesAccel[i] = event.values[i];
valuesAccelGravity[i] = (float) (0.1 * event.values[i] + 0.9 * valuesAccelGravity[i]);
valuesAccelMotion[i] = event.values[i]
- valuesAccelGravity[i];
}
break;
case Sensor.TYPE_MAGNETIC_FIELD:
for (int i=0; i < 3; i++){
valuesMagnet[i] = event.values[i];
}
break;
}
}
void getDeviceOrientation() {
SensorManager.getRotationMatrix(r, null, valuesAccel, valuesMagnet);
SensorManager.getOrientation(r, valuesResult);
valuesResult[0] = (float) Math.toDegrees(valuesResult[0]);
valuesResult[1] = (float) Math.toDegrees(valuesResult[1]);
valuesResult[2] = (float) Math.toDegrees(valuesResult[2]);
return;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question