# Strange issue with Quaternion's .mult( Vector3f v ) function, Z-axis jumps

I’m a recent arrival to JMonkey, and I’ve just started digging into Quaternions. As I understand it, they are simply rotation around an given axis (even if the math is not so simple). So I started with a simple case: taking a figure facing ‘forward’ and rotating it around the y-axis to make it turn. I’m rather confounded by the results I’ve been getting.

So when I run the following code…

public class RotationTest { public static void main(String[] args) { testRotation(); } private static void testRotation() {
``````    Vector3f initialDirection = Vector3f.UNIT_Z.negate();

// A small rotation quantity to simulate a tpf value
float amountToRotate = FastMath.PI / 16;

// Rotate 'amountToRotate' around the Y axis
Quaternion testRotation = new Quaternion(0f, 1f, 0f, amountToRotate);

// Apply rotation
// Why does this flip my z axis?
Vector3f resultingDirection = testRotation.mult(initialDirection);

System.out.println("currentDirection: " + initialDirection);
System.out.println("resultingDirection: " + resultingDirection);
}
``````

}

I get the following output…

run: currentDirection: (-0.0, -0.0, -1.0) resultingDirection: (-0.3926991, 0.0, 0.9614469) BUILD SUCCESSFUL (total time: 0 seconds)

It looks to me like a rotation is happening, but the Z-axis of the result is inverted! For what should be a small rotation it ‘jumps’ from -1.0 to +0.961…

I am new to quaternions and am not confident enough in my math to sure yet, but this doesn’t seem right. Am I interpreting it wrong?

@eadsjr said: I'm a recent arrival to JMonkey, and I've just started digging into Quaternions. As I understand it, they are simply rotation around an given axis (even if the math is not so simple). So I started with a simple case: taking a figure facing 'forward' and rotating it around the y-axis to make it turn. I'm rather confounded by the results I've been getting.

So when I run the following code…

I get the following output…

It looks to me like a rotation is happening, but the Z-axis of the result is inverted! For what should be a small rotation it ‘jumps’ from -1.0 to +0.961…

I am new to quaternions and am not confident enough in my math to sure yet, but this doesn’t seem right. Am I interpreting it wrong?

You are constructing the quaternion wrong. The ‘w’-component is not rotation angles around the given axis. That’s not how Quaternion works.

Personally I think about quaternions just as “a rotation” and don’t try to understand what the components “mean” since that is the tricky part

Thank you! This gives a more sensible result:

// Rotate 'amountToRotate' around the Y axis Quaternion testRotation = new Quaternion(); testRotation = testRotation.fromAngleAxis(amountToRotate, Vector3f.UNIT_Y);
run: currentDirection: (-0.0, -0.0, -1.0) resultingDirection: (-0.19509032, 0.0, -0.98078525) BUILD SUCCESSFUL (total time: 0 seconds)

FYI

Quaternions are actually more like a 3d sphere that appears due to projectsion from a 4dimensional space or something similar confusing

Here a 2d image showing the projection of said sphere to 2 dimensions

1 Like
@pspeed said: Obligatory: http://www.maths.ed.ac.uk/~aar/papers/hanson.pdf

That is great stuff! Thanks you!

1 Like