quaternion

 Member Function  Parameter  Return  Explain
 getElement None number x, y, z, w  
 setElement number x, y, z, w None  
 identity None None  
 inverse None None  
 isIdentity None boolean  
 length None number  
 lengthsq None number  
 normalize None None  
 rotationAxis vec axis   number angle None in degree
 rotationYawPitchRoll number yaw, pitch, roll None in degree
 rotationMatrix matrix None Builds quaternion from rotation matrix.
 toAxisAngle None vec axis   number angle in degree
 toYawPitchRoll None number yaw, pitch, roll in degree
 clone None matrix  
 Operator  Parameter  Return  Explain
 + (addition) quaternion q1, q2 quaternion  
 - (subtraction) quaternion q1, q2 quaternion  
 * (multiplication) quaternion q,  number  n quaternion  
 * (multiplication) quaternion q,   vec  v vec rotate vector by quaternion
(same with VectorTransformNormal )
 * (multiplication) quaternion q1, q2 quaternion Multiplies two quaternions.
 / (division) quaternion q,  number  n quaternion  
 == (equality) quaternion q1, q2 boolean  
 - (negation) quaternion quaternion Given a quaternion (x, y, z, w), the operation will return the quaternion (-x, -y, -z, w).
 [] (index) quaternion q   number  i number zero based index, i within (0,1,2,3)
  Lib Function  Parameter  Return  Explain
 new  [ matrix ]
 [ number x, y, z, w ]
 quaternion no parameter, or matrix, or x,y,z,w
 dot quaternion q1, q2 number Returns the dot product of two quaternions.
 VectorTransformNormal quaternion , vec vec Transforms the 3-D vector normal by the given quaternion.

Usage Example:
q = quaternion.new()
q1 = quaternion.new( matrix.new() )
q2 = quaternion.new( 0,0,0,1 )

q.rotationYawPitchRoll( 90,45, 30 )
v = vec.new(0,0,1)
v = q * v
n = quaternion.dot( q1, q2 )

print( q.getElement() )
print( q[0], q[1], q[2], q[3] )
print( q.x, q.y, q.z, q.w )

q[0] = 1; q[1] = 2; q.z = 3; q.w = 4;
q.setElement( 1, 2, 3, 4 ) -- this method is more efficient than separately set element by index

q.normalize()
m = matrix.new( q ) -- create a matrix from quaternion