Skip to content

Instantly share code, notes, and snippets.

@ishikawash
Created September 9, 2014 15:16
Show Gist options
  • Save ishikawash/7f4074875e5d8dd65e01 to your computer and use it in GitHub Desktop.
Save ishikawash/7f4074875e5d8dd65e01 to your computer and use it in GitHub Desktop.
toxiclibs: Quaternion error
{axis: [0.0,0.7078125,0.0], w: 0.70781255}
{axis: [0.0,-0.70922744,0.0], w: 0.7064004}
import toxi.geom.*;
/*
Two quaternions with same angle and same axis don't match.
One is created from axis and angle.
Another is created from matrix.
*/
void setup() {
noLoop();
Quaternion q1 = Quaternion.createFromAxisAngle(Vec3D.Y_AXIS, HALF_PI);
Matrix4x4 m = q1.toMatrix4x4();
Quaternion q2 = Quaternion.createFromMatrix(m);
println(q1);
println(q2);
}
@postspectacular
Copy link

Hey, this commit fixes this issue:
https://bitbucket.org/postspectacular/toxiclibs/commits/b247b2067b218b775958523eab411dc4c8699a1e

More generally, you'll not always get the exact same quat back from such a round trip due to gimbal lock and other possible singularities, but the final quat will produce equivalent results when applied to a 3D vector (see test include in above commit). More info here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment