Hello,

does someone know how to compare to Quaternion with only one single value?

I have got a spatial possessing a world rotation. I have got a second quaternion which describes the target rotation. I use the slerp method to perform an interpolation. Now, I do not want to interpolate “infinitely long” so I have to find a break condition. I currently try something like this…

[java]

…

if (Math.abs(slerpQuaternion.getX() - sourceWorldRotation.getX()) < 0.00001f

&& Math.abs(slerpQuaternion.getY() - sourceWorldRotation.getY()) < 0.00001f

&& Math.abs(slerpQuaternion.getZ() - sourceWorldRotation.getZ()) < 0.00001f

&& Math.abs(slerpQuaternion.getW() - sourceWorldRotation.getW()) < 0.001f) {

break;

}

…

[/java]

However, I want to have a single compare value which tells me that the quaternions are equal. There must be something like…

[java]

…

if(slerpQuaternion.inverse().mult(sourceWorldRotation).dot()<0.001f){

break;

}

…

[/java]

Is this the right way? I am not so used to quaternion maths.

Thanks a lot.

Just out of top of my head, try Math.acos(slerpQuaternion.dot(sourceWorldRotation)) < EPSILON; Quternions will have to be normalized before that.

Hello,

thanks for the answer but it doesn’t work. I think I know where the problem is. If the epilon value is too high the rotation stops before it should. If it is too low the interpolation is infinite. I think the problem is that I have to modify following code snippet…

[java]

…

slerpQuaternion.slerp(targetSpaceQuaternion.mult(pointingQuaternion), 0.1f);

…

[/java]

I have got a constant interpolation value of 0.1f. I assume that if the slerpQuaterion approaches the pointingQuaterion the difference becomes smaller. But 0.1f is associated with this difference. So it is always 0.1f interpolation of the current quaternion difference.

Thanks.

Regards,

Equi

Hello,

I have found the solution. It is not possible to test convergence of quaternions. You must transform them to angles and perform angle convergence tests…

[java]

float[] slerpQuaternionAngleS = slerpQuaternion.toAngles(null);

float[] sourceWorldRotationAngles = sourceWorldRotation.toAngles(null);

if (Math.abs(slerpQuaternionAngleS[0] - sourceWorldRotationAngles[0]) < 0.0001f

&& Math.abs(slerpQuaternionAngleS[1] - sourceWorldRotationAngles[1]) < 0.0001f

&& Math.abs(slerpQuaternionAngleS[2] - sourceWorldRotationAngles[2]) < 0.0001f) {

//If convergence is reached beyond an epislon value, set the target quaternion to have exact solution

source.setWorldRotation(targetSpaceQuaternion);

}

[/java]

Regards,

Equi