graphic-o3d-samples-o3djs-quaternions.js / js
@fileoverview This file contains various functions for quaternion arithmetic and converting between rotation matrices and quaternions. It adds them to the "quaternions" module on the o3djs object. Javascript arrays with four entries are used to represent quaternions, and functions are provided for doing operations on those. Operations are done assuming quaternions are of the form: q[0] + q[1]i + q[2]j + q[3]k and using the hamiltonian rules for multiplication as described on Brougham Bridge: i^2 = j^2 = k^2 = ijk = -1.
A Module for quaternion math. @namespace
A Quaternion. @type {!Array.<number>}
Quickly determines if the object a is a scalar or a quaternion; assumes that the argument is either a number (scalar), or an array of numbers.
parameter: {(number|!o3djs.quaternions.Quaterion)} a A number or array the type of which is in question.
returns: {string} Either the string 'Scalar' or 'Quaternion'.
Copies a quaternion.
parameter: {!o3djs.quaternions.Quaterion} q The quaternion.
returns: {!o3djs.quaternions.Quaterion} A new quaternion identical to q.
Negates a quaternion.
parameter: {!o3djs.quaternions.Quaterion} q The quaternion.
returns: {!o3djs.quaternions.Quaterion} -q.
Adds two Quaternions.
parameter: {!o3djs.quaternions.Quaterion} a Operand Quaternion.
parameter: {!o3djs.quaternions.Quaterion} b Operand Quaternion.
returns: {!o3djs.quaternions.Quaterion} The sum of a and b.
Adds a quaternion to a scalar.
parameter: {!o3djs.quaternions.Quaterion} a Operand Quaternion.
parameter: {numbers} b Operand Scalar.
returns: {!o3djs.quaternions.Quaterion} The sum of a and b.
Adds a scalar to a quaternion.
parameter: {number} a Operand scalar.
parameter: {!o3djs.quaternions.Quaterion} b Operand quaternion.
returns: {!o3djs.quaternions.Quaterion} The sum of a and b.
Subtracts two quaternions.
parameter: {!o3djs.quaternions.Quaterion} a Operand quaternion.
parameter: {!o3djs.quaternions.Quaterion} b Operand quaternion.
returns: {!o3djs.quaternions.Quaterion} The difference a - b.
Subtracts a scalar from a quaternion.
parameter: {!o3djs.quaternions.Quaterion} a Operand quaternion.
parameter: {number} b Operand scalar.
returns: {!o3djs.quaternions.Quaterion} The difference a - b.
Subtracts a quaternion from a scalar.
parameter: {number} a Operand scalar.
parameter: {!o3djs.quaternions.Quaterion} b Operand quaternion.
returns: {!o3djs.quaternions.Quaterion} The difference a - b.
Multiplies a scalar by a quaternion.
parameter: {Array} k The scalar.
parameter: {Array} q The quaternion.
returns: {Array} The product of k and q.
Multiplies a quaternion by a scalar.
parameter: {!o3djs.quaternions.Quaterion} q The Quaternion.
parameter: {number} k The scalar.
returns: {!o3djs.quaternions.Quaterion} The product of k and v.
Multiplies two quaternions.
parameter: {!o3djs.quaternions.Quaterion} a Operand quaternion.
parameter: {!o3djs.quaternions.Quaterion} b Operand quaternion.
returns: {!o3djs.quaternions.Quaterion} The quaternion product a * b.
Divides two quaternions; assumes the convention that a/b = a*(1/b).
parameter: {!o3djs.quaternions.Quaterion} a Operand quaternion.
parameter: {!o3djs.quaternions.Quaterion} b Operand quaternion.
returns: {!o3djs.quaternions.Quaterion} The quaternion quotient a / b.
Divides a Quaternion by a scalar.
parameter: {!o3djs.quaternions.Quaterion} q The quaternion.
parameter: {number} k The scalar.
returns: {!o3djs.quaternions.Quaterion} q The quaternion q divided by k.
Divides a scalar by a quaternion.
parameter: {number} a Operand scalar.
parameter: {!o3djs.quaternions.Quaterion} b Operand quaternion.
returns: {!o3djs.quaternions.Quaterion} The quaternion product.
Computes the multiplicative inverse of a quaternion.
parameter: {!o3djs.quaternions.Quaterion} q The quaternion.
returns: {!o3djs.quaternions.Quaterion} The multiplicative inverse of q.
Multiplies two objects which are either scalars or quaternions.
parameter: {(!o3djs.quaternions.Quaterion|number)} a Operand.
parameter: {(!o3djs.quaternions.Quaterion|number)} b Operand.
returns: {(!o3djs.quaternions.Quaterion|number)} The product of a and b.
Divides two objects which are either scalars or quaternions.
parameter: {(!o3djs.quaternions.Quaterion|number)} a Operand.
parameter: {(!o3djs.quaternions.Quaterion|number)} b Operand.
returns: {(!o3djs.quaternions.Quaterion|number)} The quotient of a and b.
Adds two objects which are either scalars or quaternions.
parameter: {(!o3djs.quaternions.Quaterion|number)} a Operand.
parameter: {(!o3djs.quaternions.Quaterion|number)} b Operand.
returns: {(!o3djs.quaternions.Quaterion|number)} The sum of a and b.
Subtracts two objects which are either scalars or quaternions.
parameter: {(!o3djs.quaternions.Quaterion|number)} a Operand.
parameter: {(!o3djs.quaternions.Quaterion|number)} b Operand.
returns: {(!o3djs.quaternions.Quaterion|number)} The difference of a and b.
Computes the length of a Quaternion, i.e. the square root of the sum of the squares of the coefficients.
parameter: {!o3djs.quaternions.Quaterion} a The Quaternion.
returns: {number} The length of a.
Computes the square of the length of a quaternion, i.e. the sum of the squares of the coefficients.
parameter: {!o3djs.quaternions.Quaterion} a The quaternion.
returns: {number} The square of the length of a.
Divides a Quaternion by its length and returns the quotient.
parameter: {!o3djs.quaternions.Quaterion} a The Quaternion.
returns: {!o3djs.quaternions.Quaterion} A unit length quaternion pointing in the same direction as a.
Computes the conjugate of the given quaternion.
parameter: {!o3djs.quaternions.Quaterion} q The quaternion.
returns: {!o3djs.quaternions.Quaterion} The conjugate of q.
Creates a quaternion which rotates around the x-axis by the given angle.
parameter: {number} angle The angle by which to rotate (in radians).
returns: {!o3djs.quaternions.Quaterion} The quaternion.
Creates a quaternion which rotates around the y-axis by the given angle.
parameter: {number} angle The angle by which to rotate (in radians).
returns: {!o3djs.quaternions.Quaterion} The quaternion.
Creates a quaternion which rotates around the z-axis by the given angle.
parameter: {number} angle The angle by which to rotate (in radians).
returns: {!o3djs.quaternions.Quaterion} The quaternion.
Creates a quaternion which rotates around the given axis by the given angle.
parameter: {!o3djs.math.Vector3} axis The axis about which to rotate.
parameter: {number} angle The angle by which to rotate (in radians).
returns: {!o3djs.quaternions.Quaterion} A quaternion which rotates angle radians around the axis.
Computes a 4-by-4 rotation matrix (with trivial translation component) given a quaternion. We assume the convention that to rotate a vector v by a quaternion r means to express that vector as a quaternion q by letting q = [0, v[0], v[1], v[2]] and then obtain the rotated vector by evaluating the expression (r * q) / r.
parameter: {!o3djs.quaternions.Quaterion} q The quaternion.
returns: {!o3djs.math.Matrix4} A 4-by-4 rotation matrix.
Computes a quaternion whose rotation is equivalent to the given matrix.
parameter: {!o3djs.math.Matrix4} m A 3-by-3 or 4-by-4 rotation matrix.
returns: {!o3djs.quaternions.Quaterion} A quaternion q such that quaternions.quaternionToRotation(q) is m.
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.