Reputation: 81
This one has had me scratching my head for a while. I have an accelerometer and am successfully measuring the X and Y angles with this great script: https://github.com/ozzmaker/BerryIMU/blob/master/python-BerryIMU-gryo-accel-compass/berryIMU.py
What I would like to calculate is the delta angle between the gravity vector and the Z axis (where Z is the normal vector to the plane created by the X and Y angles).
I have found some images on google and edited them to try to explain the issue. See below.
If the script from githut above calculates X and Y as follows:
import math
RAD_TO_DEG = 57.295
ACCy = (see github script for details)
ACCz = (see github script for details)
ACCx = (see github script for details)
Xangle = (math.atan2(ACCy,ACCz)*RAD_TO_DEG)
Yangle = (math.atan2(ACCz,ACCx)*RAD_TO_DEG)
How would I calculate the Z angle delta to gravity vector as shown in the image? Would it be:
Zangle = (math.atan2(ACCx,ACCy)*RAD_TO_DEG)
Upvotes: 1
Views: 958
Reputation: 8059
math.asin(ACCz / math.sqrt(ACCx ** 2 + ACCy **2 + ACCz ** 2)) * RAD_TO_DEG
might be what you're looking for.
Upvotes: 1