Quaternion angle calculation

TJHUNTER

New member
Joined
Jan 15, 2019
Messages
3
Hi,

I'm working on a programming project, in this project I'm receiving an angle as a quaternion value, I partially understand how they work but I don't find any math to get the values I need.
What I would need is the angle between a fictional line/vector going to the the quaternion point from the origin (yes I know what you are thinking, but I couldn't think of a better explanation) and the "earth" a plane that is perpendicular to the gravitational vector, in this case one of your planes of reference.
Also I would need to get the rotation of the line/vector, this time the rotation should be according to the plane perpendicular to itself.
If possible all angles should be described as an angle between -180° and 180° (that's were my troubles are from.

If someone could help me by this it would be awesome
Thank you in advanced
~TJ

In this picture γ complementary angle of the first questing and R is the secondary angle.
3dVector.jpgangles
 
Last edited:
I will ask there too, thanks for the hint.

If I find the solution I will post it here too, in the mean time, all help is still welcome.
 
> You should **always** use atan2(y,x) instead of atan(y/x). It is a common mistake. – Somos


He wrote this on an other math form were I asked this too, and that was my stupid mistake -_-
Please realize this fix is only for programming, this is not a true mathematical solution.


My new version is:


float gx = 2 * (x*z - w*y);
float gy = 2 * (w*x + y*z);
float gz = w*w - x*x - y*y + z*z;
float yaw = atan2(2*x*y - 2*w*z, 2*w*w + 2*x*x - 1); // about Z axis
float pitch = atan2(gx, sqrt(gy*gy + gz*gz)); // about Y axis
float roll = atan2(gy, gz); // about X axis

/*Serial.print(" yaw ");
Serial.print(yaw * 180/M_PI,0);*/
Serial.print(" pitch ");
Serial.print(pitch * 180/M_PI,2);
Serial.print(" sideways ");
// Please don't pay attention to the extra function I made for the project but it doesn't have to do with the problem
if(pitch > 0) Serial.println((roll * 180/M_PI) * (1/(1+pow(1.293,((pitch * 180/M_PI)-51.57)))), 2);
else if(pitch == 0) Serial.println(roll * 180/M_PI, 2);
else if(pitch < 0) Serial.println((roll * 180/M_PI) * (1/(1+pow(1.293,(((pitch) * (-180)/M_PI)-51.57)))), 2);
 
Top