Angle between Quaternion and vector

ares

New member
Joined
Nov 15, 2017
Messages
1
Hi all,
I have a simple (hard) problem. Im trying to find the angle (in Degres) between a vector and a quaternion. The vector is in 3D space but Y=0 so it lay in XZ plane while the quaternion represent the orientation in 3d space. Now, what Im trying to find is the angle that the quaternion create with the vector but i need only the angle in XZ plane and the sign +- of the angle.
Immagine.jpg
Till now I have done this but I get always positive angles (it's in JAVA)
Position currentPositionNode=new Position(0,0,0);

Position nextNode=new Position(1,0,1);
// So I have the vector between to points
nextNode.subtract(currentPositionNode);

// Quaternion values are random,not important
Quaternion myOrientation=new Quaternion( w:0.7071,x:0.7071,y:0,z:0);
myOrientation.normalize();

Quaternion invQuat=myOrientation.clone();
invQuat.inverse();

// X-axis is forward
Quaternion qNode=new Quaternion(w:0,Vector3.X.x,Vector3.X.y,Vector3.X.z);
qNode=myOrientation.multiply(qNode);
qNode=qNode.multiply(invQuat);

Vector3 myDirection=new Vector3(qNode.x,qNode.
y,qNode.z);

double angle=myDirection.angle(nextNode);
 
Top