Quaternions equal on 1 axis only

Hello guys,
I was wondering if there was a way to tell if two quaternions are equal on the Y axis only.

like I ignore the other axis, I just want their equality on the axis Y for example.

THX!!!

[java]
q.mult (Vector3f.UNIT_Y).equals (q2.mult(Vector3f.UNIT_Y);
[/java]

1 Like

oww yeahh LOL thats not stupid :smiley:

thx again wezrule!

Oh And I want them to be approximately equal,do I make a vector distance between the new calculated Y?

you can either: get the angle between them and see if it is very small (or check how close the dot product is to 1, they use the same principle), or compare the x, y, and z components, and check if they are within some tolerance/predefined value you use.

[java]if (vec.angleBetween (vec2) < 0.01) {

}

// or
if (FastMath.abs (vec.x - vec2.x) < 1E-5 && FastMath.abs(vec.y - vec2.y) < 1E-5 && FastMath.abs(vec.z - vec2.z) < 1E-5) {

}

[/java]

1 Like

THX WEZRULE! :slight_smile:

im doing this to knwo if a spacial has reached its rotation destination, so i’m doing the test every update, which one of those two is the most efficient? or maybe we dont care lol

ok yeh, then either one will suffice. I always go with the more readable one (but your choice).

Also I forgot to mention, don’t forget to normalize the vectors first before calling these

1 Like

OMG! and I was just wondering why it didnt work! lol :smiley:

here is my final code :
[java]
rotationDestination.mult(Vector3f.UNIT_Y).normalize().angleBetween(spatial.getLocalRotation().mult(Vector3f.UNIT_Y).normalize()) > rotationPrecision[/java]

this is to know if my spatial is still rotating

1 Like