B2G/gecko/browser/devtools/tilt/TiltMath.jsm
/**
   * Calculate the W component of a quat4 from the X, Y, and Z components.
   * Assumes that quaternion is 1 unit in length.
   * Any existing W component will be ignored.
   *
   * @param {Array} aQuat
   *                quat4 to calculate W component of
   * @param {Array} aDest
   *                optional, quat4 receiving calculated values
   *                if not specified result is written to the first operand
   *
   * @return {Array} the destination quat if specified, first operand otherwise
   */
Calculate the W component of a quat4 from the X, Y, and Z components.
Assumes that quaternion is 1 unit in length.
Any existing W component will be ignored.

@param {Array} aQuat
quat4 to calculate W component of
@param {Array} aDest
optional, quat4 receiving calculated values
if not specified result is written to the first operand

@return {Array} the destination quat if specified, first operand otherwise
Calculate the W component of a quat4 from the X Y and Z components . Assumes that quaternion is 1 unit in length . Any existing W component will be ignored . @param { Array } aQuat quat4 to calculate W component of @param { Array } aDest optional quat4 receiving calculated values if not specified result is written to the first operand @return { Array } the destination quat if specified first operand otherwise
function Q4_calculateW(aQuat, aDest)
  {
    if (!aDest) {
      aDest = aQuat;
    }
    let x = aQuat[0];
    let y = aQuat[1];
    let z = aQuat[2];
    aDest[0] = x;
    aDest[1] = y;
    aDest[2] = z;
    aDest[3] = -Math.sqrt(Math.abs(1 - x * x - y * y - z * z));
    return aDest;
  }
function Q4_calculateW ( aQuat , aDest ) { if ( ! aDest ) { aDest = aQuat ; } let x = aQuat [ 0 ] ; let y = aQuat [ 1 ] ; let z = aQuat [ 2 ] ; aDest [ 0 ] = x ; aDest [ 1 ] = y ; aDest [ 2 ] = z ; aDest [ 3 ] = - Math . sqrt ( Math . abs ( 1 - x * x - y * y - z * z ) ) ; return aDest ; }
Calculate the W component of a quat4 from the X, Y, and Z components.
Calculate the W component of a quat4 from the X Y and Z components .