636
2012-11-06 23:29:07 +0100
Quaternion multiplication unexpected behavior
2012-11-11 09:14:03 +0100
1
1
3
JogAmp
Jogl
graph
2
All
all
RESOLVED
FIXED
---
critical
---
1
fwdk98003
sgothel
rami.santina
sgothel
---
jogl 944562a9600598dfa8a23f96f568fde999e1eca3
jogl 5fafc1ac360333645b807dcd8dff0c0a655ea439
---
oldest_to_newest
1951
0
fwdk98003
2012-11-06 23:29:07 +0100
I am using JOGL 2.0 rc 10.
I tried using Quaternion class that was implemented in jogamp.graph.math.MathFloat.Quaternion and I noticed an error in mult(Quaternion).
I am not a Quaternion expert but according to all math site online quaternion multiplication is done as follows:
Let Q1 and Q2 be two quaternions, which are defined, respectively, as (w1, x1, y1, z1) and (w2, x2, y2, z2).
(Q1 * Q2).w = (w1w2 - x1x2 - y1y2 - z1z2)
(Q1 * Q2).x = (w1x2 + x1w2 + y1z2 - z1y2)
(Q1 * Q2).y = (w1y2 - x1z2 + y1w2 + z1x2)
(Q1 * Q2).z = (w1z2 + x1y2 - y1x2 + z1w2
http://en.wikipedia.org/wiki/Quaternion
http://www.cprogramming.com/tutorial/3d/quaternions.html
http://mathworld.wolfram.com/Quaternion.html
In Quaternion class, mult(Quaternion) is currently defined as:
public void mult(Quaternion q)
{
float w1 = w*q.w - (x*q.x + y*q.y + z*q.z);
float x1 = w*q.z + q.w*z + y*q.z - z*q.y;
float y1 = w*q.x + q.w*x + z*q.x - x*q.z;
float z1 = w*q.y + q.w*y + x*q.y - y*q.x;
w = w1;
x = x1;
y = y1;
z = z1;
}
I believe this multiplication is incorrect and it rotated my jogl model unpredictively. Also, according to quaternion definition, quaternion multiplication are not commutative!!! (ie: q.w*z is different from z*q.w)
I override the mult(Quaternion) with the definition of quaternion multiplication and it behaves as expected:
public void mult(Quaternion q)
{
float w1 = w*q.w - x*q.x - y*q.y - z*q.z;
float x1 = w*q.x + x*q.w + y*q.z - z*q.y;
float y1 = w*q.y - x*q.z + y*q.w + x*q.x;
float z1 = w*q.z + x*q.y - y*q.x + y*q.w;
w = w1;
x = x1;
y = y1;
z = z1;
}
Thank you in advance
1953
1
sgothel
2012-11-07 01:57:38 +0100
Thank you for your detailed bug report, inclusive references and fix.
Assigned to the original author, Rami Santina.
Let's wait until Rami has a chance to reply.
1954
2
sgothel
2012-11-07 01:59:04 +0100
@Rami: We may want to merge math util stuff (FloatUtil, ..) somehow more central ?
1956
3
rami.santina
2012-11-07 12:04:30 +0100
Yup thats correct, the fix is verified. Its good that we havent used this method in graph yet :) Great Catch. Thanks.
PS: its true quaternions are not commutative, but thats regarding q1*12 vs q2*q1, thus has nothing to do with quat. premitives. since w1*w2 will always give same result :)
@Sven, can you merge in this fix?
1957
4
rami.santina
2012-11-07 15:59:41 +0100
Yup thats correct, the fix is verified. Its good that we havent used this method in graph yet :) Great Catch. Thanks.
PS: its true quaternions are not commutative, but thats regarding q1*12 vs q2*q1, thus has nothing to do with quat. premitives. since w1*w2 will always give same result :)
@Sven, can you merge in this fix?
1958
5
sgothel
2012-11-07 16:32:02 +0100
(In reply to comment #4)
> @Sven, can you merge in this fix?
Yes.
1959
6
sgothel
2012-11-07 16:33:15 +0100
BTW ... can we have a unit test for this ? :)
I will also validate the package location of out float/math stuff.
1960
7
fwdk98003
2012-11-07 18:32:34 +0100
(In reply to comment #4)
> PS: its true quaternions are not commutative, but thats regarding q1*12 vs
> q2*q1, thus has nothing to do with quat. premitives. since w1*w2 will always
> give same result :)
Thank you for clearing that up.
1970
8
sgothel
2012-11-11 09:14:03 +0100
Fixed w/ 944562a9600598dfa8a23f96f568fde999e1eca3 - setting Tek as author of commit.
Also went fwd to reorg. math util locations, see commit 5fafc1ac360333645b807dcd8dff0c0a655ea439,
etc ..