How do you calculate the amount the phone has rotated?, where the “zero degrees” is something you specify.
For example, say you have your phone flat infront of you on a table in a portrait position – let’s call that “zero degrees”.
You rotate the phone to the right so that it is now landscape (top of phone pointing right) – that would be “90 degrees”.
During this rotation, the phone would’ve rotated 20, 30, 40 etc degrees
So far, I’ve found the way to detect phone rotation is via accelerometer and compass, ie “getAzimuth()“. However, “zero degrees” is always North.
Is there a way to calculate the rotation of the phone not in relation to cardinal directions?
Notes:
- Using libgdx, though the sensor behaviour shouldn’t differ that much
- “
getRotation()” seems to be able to determine rotations at 0, 90, 270 degrees but not values in between - Phone I’m using doesn’t have gyroscope, and ideally solution won’t need gyroscope either
Thanks 🙂
You can calculate an angle between any two vectors. If one of them has direction to North (with 0 azimuth) – this is just a special case. You can choose any other angle as base and just subtract it from next measurements.
There are no means to tell the mobile to have 0 azimuth not pointing to North. BTW, “rotation” is about screen orientation, this is a side product of mobile rotation.