Java – getting two quaternion angles
Well, so I tried to get the angle of two quaternions, it's almost perfect, but then it's from
evec angle: 237.44999653311922 evec angle: 119.60001380112993
And I can't figure out why to my life (Note: EVEC is an old variable name, which is only left in the printed matter)
Anyway, this is my code:
FloatBuffer fb = BufferUtils.createFloatBuffer(16);
// get the current modelview matrix
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX,fb);
Matrix4f mvm = new Matrix4f();
mvm.load(fb);
Quaternion qmv2 = new Quaternion();
Matrix4f imvm = new Matrix4f();
Matrix4f.invert(mvm,imvm);
qmv2.setFromMatrix(imvm);
qmv2.normalise();
Matrix3f nil = new Matrix3f();
nil.setIdentity();
Quaternion qnil = new Quaternion();
qnil.setFromMatrix(nil);
qnil.normalise();
float radAngle = (float)(2.0 * Math.acos(Quaternion.dot(qmv2,qnil)));
System.out.println("evec angle: " + Math.todegrees(radAngle));
How to make it jump from 237 to 119 and continue to rise to 360?
Solution
First, what does the angle between two four-dimensional vectors (= quaternions) mean to geometry? You can calculate it, but the result may be meaningless Maybe you're looking for the angle between the rotation axes represented by two quaternions?
Second, you have a mistake:
float radAngle = (float)(2.0 * Math.acos(Quaternion.dot(qmv2,qnil)));
^^^^^
The result of ACOS is angle Don't multiply by 2
Third, the angle between two vectors in 3D or 4D space will never be greater than 180 ° It can be on the plane because the plane imposes a direction In 3D space, you must define any direction as "up" to obtain an angle higher than 180 °
