Skip to content

Instantly share code, notes, and snippets.

@mstefanko
Created March 28, 2011 13:21
Show Gist options
  • Save mstefanko/890434 to your computer and use it in GitHub Desktop.
Save mstefanko/890434 to your computer and use it in GitHub Desktop.
Get tilt from accelerometer values
double accX = -x/SensorManager.GRAVITY_EARTH;
double accY = -y/SensorManager.GRAVITY_EARTH;
double accZ = z/SensorManager.GRAVITY_EARTH;
double totAcc = Math.sqrt((accX*accX)+(accY*accY)+(accZ*accZ));
double tiltX = Math.asin(accX/totAcc);
double tiltY = Math.asin(accY/totAcc);
double tiltZ = Math.asin(accZ/totAcc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment