Search code examples
rotationquaternionsfamo.us

famo.us quaternion rotation around z axis


As far as I know a quaternion is a set of four values (W X Y Z) that are used to specify a rotation in 3D space. For a given axis (x y z) and angle (α), the quaternion representing a rotation around the axis from the origin (0,0,0) to (x,y,z). So a rotation of 90 degrees about the z axis (0 0 1) should be:

var quaternion = new Quaternion(Math.PI/2, 0, 0, 1);

but famo.us turns it for ~60 degrees...

I've also tried var quaternion = new Quaternion(90, 0, 0, 1); but in this case famo.us turns it for ~5 degrees

is it a bug of the framework?
How should I use it to turn it on 90 degreez around z axis?
Documentation is still totally useless..


Solution

  • Try using this method Quaternion.makeFromAngleAndAxis(angle, v) I have found this to be the most straight forward approach to making it a little more readable and useable.

    Example jsBin

    Where

    var degrees = 90;    
    var angle = Math.PI/180 * degrees;
    var v = new Vector(0, 0, 1);
    
    var quaternion = new Quaternion();
    quaternion.makeFromAngleAndAxis(angle, v);
    

    ...To get the transform

    quaternion.getTransform();
    

    Something to remember from Math Class

    A circle has 360 degrees. Each degree is represented by the unit circumference of a circle 2 * PI * r. We will assume we have a radius of 1. So divide your total circumference by 360 and you get one degrees 2PI/360 or PI/180.

    In Summary:

    • one degrees of our circle is = Math.PI/180
    • your angle of direction is = Math.PI/180 * degrees