famo.us quaternion rotation around z axis

As far as I know a quaternion is a set of four values (WXYZ) that are used to specify a rotation in 3D space. For a given axis (xyz) 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..


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

  • 刚刚在一篇wiki文章中找到答案:

    var angle = Math.PI/2;
    var axis = [0,0,1];
    
    var w = Math.cos(.5 * angle);
    var x = axis[0] * Math.sin(.5 * angle);
    var y = axis[1] * Math.sin(.5 * angle);
    var z = axis[2] * Math.sin(.5 * angle);
    var quaternion = new Quaternion(w, x, y, z);
    

    try this transformation - Transform.rotateZ(angle);

    Refer to - http://famo.us/docs/reference/pages/0.3/transforms.html

    链接地址: http://www.djcxy.com/p/81864.html

    上一篇: 使用特征根据欧拉角旋转四元数

    下一篇: 四轴绕z轴旋转