java – How to Isolate Gravity on the Accelerometer

Question:

I'm developing an app where the user needs to shake the phone in all directions and the smartphone needs to keep its orientation stable in the meantime. The problem is that all the ways to get spatial orientation like TYPE_ROTATION_VECTOR , TYPE_GEOMAGNETIC_ROTATION_VECTOR , and even getRotationMatrix() use the accelerometer together, and when the user moves the cell the direction of gravity changes due to lateral forces.

Is there some kind of filter to isolate gravity? That is, isolating the user's movements so that the sensor returns only the direction of gravity to improve orientation.

There are several posts about removing gravity, but nothing about isolating it.

Answer:

You can use the function getInclination( float[] I ) , it gives the slope only, in angle (radians). That is, it gives the slope in relation to the force of gravity.

float inclinacao = SensorManager.getInclination(inclinationMatrix);

So you can adjust the screen rotation according to the angle.

Scroll to Top
AllEscort