API Docs for: 6.0.1
Show:

Quaternion Class

Quaternion

Instantiation

  • scrawl.makeQuaternion()

Purpose

  • To hold quaternion (3d rotation) data

Constructor

Quaternion

(
  • [items]
)

Parameters:

  • [items] Object optional

    Key:value Object argument for setting attributes

Methods

checkNormal

(
  • [tolerance]
)

Check to see if quaternion is a unit quaternion, within permitted tolerance

Parameters:

  • [tolerance] Number optional

    Tolerance value; default: 0

Returns:

True if quaternion is a normalized quaternion; false otherwise

conjugate

()

Conjugate (reverse) value for this quaternion

Returns:

Conjugated quaternion

getAngle

(
  • [degree]
)

Retrieve rotational component of this quaternion

Parameters:

  • [degree] Boolean optional

    Returns rotation in degrees if true; false (radians) by default

Returns:

Rotation angle

getAxis

()

Retrieve axis component of this quaternion

Returns:

Normalized Vector (scrawl.v Vector)

getEulerAngles

() Pitch:Number, yaw:Number, roll:Number

Retrieve rotations (Euler angles) from a quaternion

Returns:

Pitch:Number, yaw:Number, roll:Number:

Object in the form

getEulerRoll

()

Retrieve Euler roll value from a quaternion

Returns:

Number

getMagnitude

()

Calculate magnitude of a quaternion

Returns:

Magnitude value

getScalar

()

Retrieve quaternion's scalar (rotation around axis) component

Returns:

Number - scalar component of this quaternion

getVector

()

Retrieve quaternion's vector (rotation axis) component

Returns:

Vector component

getVectorMultiply

(
  • item
)
chainable

Multiply this quaternion by a Vector

Quaternion multiplication is not comutative - arithmetic is thisitem, not itemthis

Parameters:

  • item Vector

    Vector to multiply this quaternion by

Returns:

This

makeFromEuler

(
  • [items]
)

Build a quaternion from Euler angle values

Argument object can be in the form, where all values (which default to 0) are in degrees:

  • {pitch:Number, yaw:Number, roll:Number}
  • {x:Number, y:Number, z:Number}
  • or a mixture of the two

Parameters:

  • [items] Object optional

    Key:value Object argument for setting attributes

Returns:

New quaternion

Example:

var myQuart = scrawl.quaternion.makeFromEuler({
    roll: 30,
    pitch: 90,
    yaw: 125,
    });

makeQuaternion

(
  • [items]
)

A factory function to build a Quaternion object from Euler angle values

Argument object can be in the following form, where all values (which default to 0) are in degrees:

  • {pitch:Number, yaw:Number, roll:Number}
  • {x:Number, y:Number, z:Number}
  • or a mixture of the two

Parameters:

  • [items] Object optional

    Key:value Object argument for setting attributes

Returns:

New quaternion

Example:

var myQuart = scrawl.makeQuaternion({
    pitch: 90,
    yaw: 10,
    });

newQuaternion

() deprecated

Alias for makeQuaternion()

normalize

() chainable

Normalize the quaternion

Returns:

This

quaternionAdd

(
  • item
)
chainable

Add a quaternion to this quaternion

Parameters:

  • item Quaternion

    Quaternion to be added to this quaternion

Returns:

This

quaternionMultiply

(
  • item
)
chainable

Multiply this quaternion by a second quaternion

Quaternion multiplication is not comutative - arithmetic is thisitem, not itemthis

Parameters:

  • item Quaternion

    Quaternion to multiply this quaternion by

Returns:

This

quaternionRotate

(
  • item
)
chainable

Rotate this quaternion by another quaternion

Quaternion multiplication is not comutative - arithmetic is item (representing the local rotation to be applied) this, not this item (for which, use quaternionMultiply)

Parameters:

  • item Quaternion

    Quaternion to rotate this quaternion by

Returns:

This

quaternionSubtract

(
  • item
)
chainable

Subtract a quaternion from this quaternion

Parameters:

  • item Quaternion

    Quaternion to be subtracted from this quaternion

Returns:

This

scalarDivide

(
  • item
)
chainable

Divide quaternion by a scalar value

Parameters:

  • item Number

    Value to divide quaternion by

Returns:

This

scalarMultiply

(
  • item
)

Multiply quaternion by a scalar value

Parameters:

  • item Number

    Value to multiply quaternion by

Returns:

This

set

(
  • items
)

Set the values for this quaternion

Argument object can contain the following attributes:

  • for the scalar (n) value, scalar or n (Number)
  • for the vector (v) value, vector or v (Vector object, or object containing xyz attribnutes)
  • for the x value (v.x), x (Number)
  • for the y value (v.y), y (Number)
  • for the z value (v.z), z (Number)

If the argument object includes values for pitch, yaw or roll, the set will be performed via the setFromEuler() function

Argument can also be either an existing Quaternion object, or an existing Vector object - for vectors, the scalar value will be set to 0

Parameters:

  • items Object

    Object containing key:value attributes

Returns:

Amended quaternion

setFromEuler

(
  • [items]
)

Set quaternion with Euler angle values

Argument object can be in the form, where all values (which default to 0) are in degrees:

  • {pitch:Number, yaw:Number, roll:Number}
  • {x:Number, y:Number, z:Number}
  • or a mixture of the two

Parameters:

  • [items] Object optional

    Key:value Object argument for setting attributes

Returns:

New quaternion

Example:

var myQuart = scrawl.quaternion.setFromEuler({
    roll: 30,
    pitch: 90,
    yaw: 125,
    });

setFromQuaternion

(
  • item
)
chainable

Set the values for this quaternion based on the values of the argument quaternion

Parameters:

Returns:

This

setFromVector

(
  • item
)
chainable

Set the values for this quaternion based on the values of the reference vector

Parameters:

  • item Vector

    Reference vector

Returns:

This

vectorRotate

(
  • item
)

Rotate a Vector by this quaternion

Parameters:

  • item Vector

    Vector to be rotated by this quaternion

Returns:

Vector (amended argument); false on failure

zero

() chainable

set to zero quaternion (n = 1)

Returns:

This

Properties

n

Number

3d rotation value

Default: 1

name

String

Quaternion name

Default: 'generic'

scrawl.work.workquat

Object private

Object containing a set of quaternions, for calculations

type

String final

Default: 'Quaternion'

v

Vector

3d rotation axis

Default: {x:0, y:0, z:0}