Options
All
• Public
• Public/Protected
• All

# Class Quaternion

• Quaternion

## Constructors

• new Quaternion(x?: number, y?: number, z?: number, w?: number): Quaternion
• Creates a new Quaternion from the given floats

#### Parameters

• ##### Optional x: number

defines the first component (0 by default)

• ##### Optional y: number

defines the second component (0 by default)

• ##### Optional z: number

defines the third component (0 by default)

• ##### Optional w: number

defines the fourth component (1.0 by default)

## Accessors

• get w(): number
• set w(value: number): void
• Gets or sets the w coordinate

#### Returns number

• Gets or sets the w coordinate

#### Returns void

• get x(): number
• set x(value: number): void
• Gets or sets the x coordinate

#### Returns number

• Gets or sets the x coordinate

#### Returns void

• get y(): number
• set y(value: number): void
• Gets or sets the y coordinate

#### Returns number

• Gets or sets the y coordinate

#### Returns void

• get z(): number
• set z(value: number): void
• Gets or sets the z coordinate

#### Returns number

• Gets or sets the z coordinate

## Methods

• Adds two quaternions Example Playground https://playground.babylonjs.com/#L49EJ7#10

#### Parameters

• ##### other: DeepImmutableObject<Quaternion>

defines the second operand

#### Returns Quaternion

a new quaternion as the addition result of the given one and the current quaternion

• Add a quaternion to the current one Example Playground https://playground.babylonjs.com/#L49EJ7#11

#### Returns Quaternion

the current quaternion

• asArray(): number[]
• Copy the quaternion to an array Example Playground https://playground.babylonjs.com/#L49EJ7#13

#### Returns number[]

a new array populated with 4 elements from the quaternion coordinates

• Clone the current quaternion Example Playground https://playground.babylonjs.com/#L49EJ7#12

#### Returns Quaternion

a new quaternion copied from the current one

• Conjugates in place the current quaternion Example Playground https://playground.babylonjs.com/#L49EJ7#82

#### Returns Quaternion

the current updated quaternion

• conjugateToRef<T>(ref: T): T
• Conjugates the current quaternion and stores the result in the given quaternion Example Playground https://playground.babylonjs.com/#L49EJ7#81

#### Parameters

• ##### ref: T

defines the target quaternion

#### Returns T

result input

• Copy a quaternion to the current one Example Playground https://playground.babylonjs.com/#L49EJ7#86

#### Parameters

• ##### other: DeepImmutableObject<Quaternion>

defines the other quaternion

#### Returns Quaternion

the updated current quaternion

• copyFromFloats(x: number, y: number, z: number, w: number): Quaternion
• Updates the current quaternion with the given float coordinates Example Playground https://playground.babylonjs.com/#L49EJ7#87

#### Parameters

• ##### x: number

defines the x coordinate

• ##### y: number

defines the y coordinate

• ##### z: number

defines the z coordinate

• ##### w: number

defines the w coordinate

#### Returns Quaternion

the updated current quaternion

• Check if two quaternions are equals Example Playground https://playground.babylonjs.com/#L49EJ7#38

#### Parameters

• ##### otherQuaternion: DeepImmutableObject<Quaternion>

defines the second operand

#### Returns boolean

true if the current quaternion and the given one coordinates are strictly equals

• Gets a boolean if two quaternions are equals (using an epsilon value) Example Playground https://playground.babylonjs.com/#L49EJ7#37

#### Parameters

• ##### otherQuaternion: DeepImmutableObject<Quaternion>

defines the other quaternion

• ##### Optional epsilon: number

defines the minimal distance to consider equality

#### Returns boolean

true if the given quaternion coordinates are close to the current ones by a distance of epsilon.

• Updates the current quaternion from the given rotation matrix values Example Playground https://playground.babylonjs.com/#L49EJ7#41

#### Parameters

• ##### matrix: DeepImmutableObject<Matrix>

defines the source matrix

#### Returns Quaternion

the current updated quaternion

• getClassName(): string
• Gets the class name of the quaternion

#### Returns string

the string "Quaternion"

• getHashCode(): number
• Gets a hash code for this quaternion

#### Returns number

the quaternion hash code

• length(): number
• lengthSquared(): number
• Gets squared length of current quaternion Example Playground https://playground.babylonjs.com/#L49EJ7#29

#### Returns number

the quaternion length (float)

• Multiplies two quaternions Example Playground https://playground.babylonjs.com/#L49EJ7#43

#### Parameters

• ##### q1: DeepImmutableObject<Quaternion>

defines the second operand

#### Returns Quaternion

a new quaternion set as the multiplication result of the current one with the given one "q1"

• Updates the current quaternion with the multiplication of itself with the given one "q1" Example Playground https://playground.babylonjs.com/#L49EJ7#46

#### Parameters

• ##### q1: DeepImmutableObject<Quaternion>

defines the second operand

#### Returns Quaternion

the currentupdated quaternion

• Sets the given "result" as the the multiplication result of the current one with the given one "q1" Example Playground https://playground.babylonjs.com/#L49EJ7#45

#### Parameters

• ##### q1: DeepImmutableObject<Quaternion>

defines the second operand

• ##### result: T

defines the target quaternion

#### Returns T

the current quaternion

• Normalize in place the current quaternion Example Playground https://playground.babylonjs.com/#L49EJ7#54

#### Returns Quaternion

the current updated quaternion

• Normalize a copy of the current quaternion Example Playground https://playground.babylonjs.com/#L49EJ7#55

#### Returns Quaternion

the normalized quaternion

• Multiplies the current quaternion by a scale factor Example Playground https://playground.babylonjs.com/#L49EJ7#88

#### Parameters

• ##### value: number

defines the scale factor

#### Returns Quaternion

a new quaternion set by multiplying the current quaternion coordinates by the float "scale"

• scaleAndAddToRef<T>(scale: number, result: T): T
• Scale the current quaternion values by a factor and add the result to a given quaternion Example Playground https://playground.babylonjs.com/#L49EJ7#91

#### Parameters

• ##### scale: number

defines the scale factor

• ##### result: T

defines the Quaternion object where to store the result

#### Returns T

result input

• Multiplies in place the current quaternion by a scale factor Example Playground https://playground.babylonjs.com/#L49EJ7#90

#### Parameters

• ##### value: number

defines the scale factor

#### Returns Quaternion

the current modified quaternion

• scaleToRef<T>(scale: number, result: T): T
• Scale the current quaternion values by a factor and stores the result to a given quaternion Example Playground https://playground.babylonjs.com/#L49EJ7#89

#### Parameters

• ##### scale: number

defines the scale factor

• ##### result: T

defines the Quaternion object where to store the result

#### Returns T

result input

• set(x: number, y: number, z: number, w: number): Quaternion
• Updates the current quaternion from the given float coordinates Example Playground https://playground.babylonjs.com/#L49EJ7#56

#### Parameters

• ##### x: number

defines the x coordinate

• ##### y: number

defines the y coordinate

• ##### z: number

defines the z coordinate

• ##### w: number

defines the w coordinate

#### Returns Quaternion

the updated current quaternion

• Subtract two quaternions Example Playground https://playground.babylonjs.com/#L49EJ7#57

#### Parameters

• ##### other: Quaternion

defines the second operand

#### Returns Quaternion

a new quaternion as the subtraction result of the given one from the current one

• Subtract a quaternion to the current one Example Playground https://playground.babylonjs.com/#L49EJ7#58

#### Parameters

• ##### other: DeepImmutableObject<Quaternion>

defines the quaternion to subtract

#### Returns Quaternion

the current quaternion

• Stores from the starting index in the given array the Quaternion successive values Example Playground https://playground.babylonjs.com/#L49EJ7#59

#### Parameters

• ##### array: FloatArray

defines the array where to store the x,y,z,w components

• ##### Optional index: number

defines an optional index in the target array to define where to start storing values

#### Returns Quaternion

the current Quaternion object

• toEulerAnglesToRef<T>(result: T): T
• toRotationMatrix<T>(result: T): T
• Updates the given rotation matrix with the current quaternion values Example Playground https://playground.babylonjs.com/#L49EJ7#67

#### Parameters

• ##### result: T

defines the target matrix

#### Returns T

the current unchanged quaternion

• toString(): string
• Gets a string representation for the current quaternion

#### Returns string

a string with the Quaternion coordinates

• Checks if the orientations of two rotation quaternions are close to each other Example Playground https://playground.babylonjs.com/#L49EJ7#60

#### Parameters

• ##### quat0: DeepImmutableObject<Quaternion>

defines the first quaternion to check

• ##### quat1: DeepImmutableObject<Quaternion>

defines the second quaternion to check

• ##### Optional epsilon: number

defines closeness, 0 same orientation, 1 PI apart, default 0.1

#### Returns boolean

true if the two quaternions are close to each other within epsilon

• Returns the dot product (float) between the quaternions "left" and "right" Example Playground https://playground.babylonjs.com/#L49EJ7#61

#### Parameters

• ##### left: DeepImmutableObject<Quaternion>

defines the left operand

• ##### right: DeepImmutableObject<Quaternion>

defines the right operand

#### Returns number

the dot product

• Creates a new quaternion from data stored into an array Example Playground https://playground.babylonjs.com/#L49EJ7#63

#### Parameters

• ##### array: DeepImmutableObject<ArrayLike<number>>

defines the data source

• ##### Optional offset: number

defines the offset in the source array where the data starts

#### Returns Quaternion

a new quaternion

• Updates the given quaternion "result" from the starting index of the given array. Example Playground https://playground.babylonjs.com/#L49EJ7#64

#### Parameters

• ##### array: DeepImmutableObject<ArrayLike<number>>

the array to pull values from

• ##### offset: number

the offset into the array to start at

• ##### result: T

the quaternion to store the result in

#### Returns T

result input

• FromEulerAngles(x: number, y: number, z: number): Quaternion
• Create a quaternion from Euler rotation angles Example Playground https://playground.babylonjs.com/#L49EJ7#33

Pitch

Yaw

Roll

#### Returns Quaternion

the new Quaternion

• FromEulerAnglesToRef<T>(x: number, y: number, z: number, result: T): T
• Updates a quaternion from Euler rotation angles Example Playground https://playground.babylonjs.com/#L49EJ7#34

#### Parameters

Pitch

Yaw

Roll

• ##### result: T

the quaternion to store the result

#### Returns T

the updated quaternion

• Create a quaternion from Euler rotation vector Example Playground https://playground.babylonjs.com/#L49EJ7#35

#### Parameters

• ##### vec: DeepImmutableObject<Vector3>

the Euler vector (x Pitch, y Yaw, z Roll)

#### Returns Quaternion

the new Quaternion

• Updates a quaternion from Euler rotation vector Example Playground https://playground.babylonjs.com/#L49EJ7#36

#### Parameters

• ##### vec: DeepImmutableObject<Vector3>

the Euler vector (x Pitch, y Yaw, z Roll)

• ##### result: T

the quaternion to store the result

#### Returns T

the updated quaternion

• Creates a new rotation value to orient an object to look towards the given forward direction, the up direction being oriented like "up". This function works in left handed mode Example Playground https://playground.babylonjs.com/#L49EJ7#96

#### Parameters

• ##### forward: DeepImmutableObject<Vector3>

defines the forward direction - Must be normalized and orthogonal to up.

• ##### up: DeepImmutableObject<Vector3>

defines the up vector for the entity - Must be normalized and orthogonal to forward.

#### Returns Quaternion

A new quaternion oriented toward the specified forward and up.

• Creates a new rotation value to orient an object to look towards the given forward direction with the up direction being oriented like "up", and stores it in the target quaternion. This function works in left handed mode Example Playground https://playground.babylonjs.com/#L49EJ7#97

#### Parameters

• ##### forward: DeepImmutableObject<Vector3>

defines the forward direction - Must be normalized and orthogonal to up.

• ##### up: DeepImmutableObject<Vector3>

defines the up vector for the entity - Must be normalized and orthogonal to forward.

• ##### ref: T

defines the target quaternion.

#### Returns T

result input

• Creates a new rotation value to orient an object to look towards the given forward direction, the up direction being oriented like "up". This function works in right handed mode Example Playground https://playground.babylonjs.com/#L49EJ7#98

#### Parameters

• ##### forward: DeepImmutableObject<Vector3>

defines the forward direction - Must be normalized and orthogonal to up.

• ##### up: DeepImmutableObject<Vector3>

defines the up vector for the entity - Must be normalized and orthogonal to forward.

#### Returns Quaternion

A new quaternion oriented toward the specified forward and up.

• Creates a new rotation value to orient an object to look towards the given forward direction with the up direction being oriented like "up", and stores it in the target quaternion. This function works in right handed mode Example Playground https://playground.babylonjs.com/#L49EJ7#105

#### Parameters

• ##### forward: DeepImmutableObject<Vector3>

defines the forward direction - Must be normalized and orthogonal to up.

• ##### up: DeepImmutableObject<Vector3>

defines the up vector for the entity - Must be normalized and orthogonal to forward.

• ##### ref: T

defines the target quaternion.

#### Returns T

result input

• Creates a new quaternion from a rotation matrix Example Playground https://playground.babylonjs.com/#L49EJ7#101

#### Parameters

• ##### matrix: DeepImmutableObject<Matrix>

defines the source matrix

#### Returns Quaternion

a new quaternion created from the given rotation matrix values

• Updates the given quaternion with the given rotation matrix values Example Playground https://playground.babylonjs.com/#L49EJ7#102

#### Parameters

• ##### matrix: DeepImmutableObject<Matrix>

defines the source matrix

• ##### result: T

defines the target quaternion

#### Returns T

result input

• Updates a quaternion so that it rotates vector vecFrom to vector vecTo Example Playground - https://playground.babylonjs.com/#L49EJ7#70

#### Parameters

• ##### vecFrom: DeepImmutableObject<Vector3>

defines the direction vector from which to rotate

• ##### vecTo: DeepImmutableObject<Vector3>

defines the direction vector to which to rotate

• ##### result: T

the quaternion to store the result

#### Returns T

the updated quaternion

#### Parameters

• ##### value1: DeepImmutable<T>

defines first quaternion

• ##### tangent1: DeepImmutableObject<Quaternion>

defines the incoming tangent

• ##### value2: DeepImmutableObject<Quaternion>

defines second quaternion

• ##### tangent2: DeepImmutableObject<Quaternion>

defines the outgoing tangent

• ##### amount: number

defines the target quaternion

#### Returns T

the new interpolated quaternion

• Returns a new Quaternion which is the 1st derivative of the Hermite spline defined by the quaternions "value1", "value2", "tangent1", "tangent2". Example Playground https://playground.babylonjs.com/#L49EJ7#48

#### Parameters

• ##### value1: DeepImmutable<T>

defines the first control point

• ##### tangent1: DeepImmutableObject<Quaternion>

defines the first tangent

• ##### value2: DeepImmutableObject<Quaternion>

defines the second control point

• ##### tangent2: DeepImmutableObject<Quaternion>

defines the second tangent

• ##### time: number

define where the derivative must be done

#### Returns T

1st derivative

• Update a Quaternion with the 1st derivative of the Hermite spline defined by the quaternions "value1", "value2", "tangent1", "tangent2". Example Playground https://playground.babylonjs.com/#L49EJ7#49

#### Parameters

• ##### value1: DeepImmutableObject<Quaternion>

defines the first control point

• ##### tangent1: DeepImmutableObject<Quaternion>

defines the first tangent

• ##### value2: DeepImmutableObject<Quaternion>

defines the second control point

• ##### tangent2: DeepImmutableObject<Quaternion>

defines the second tangent

• ##### time: number

define where the derivative must be done

• ##### result: T

define where to store the derivative

#### Returns T

result input

• Creates an identity quaternion

#### Returns Quaternion

the identity quaternion

• Inverse a given quaternion Example Playground https://playground.babylonjs.com/#L49EJ7#103

#### Parameters

• ##### q: DeepImmutable<T>

defines the source quaternion

#### Returns T

a new quaternion as the inverted current quaternion

• Inverse a given quaternion Example Playground https://playground.babylonjs.com/#L49EJ7#104

#### Parameters

• ##### q: Quaternion

defines the source quaternion

• ##### result: T

the quaternion the result will be stored in

#### Returns T

the result quaternion

• Gets a boolean indicating if the given quaternion is identity

#### Parameters

• ##### quaternion: DeepImmutableObject<Quaternion>

defines the quaternion to check

#### Returns boolean

true if the quaternion is identity

• RotationAlphaBetaGamma(alpha: number, beta: number, gamma: number): Quaternion
• Creates a new quaternion from the given Euler float angles expressed in z-x-z orientation Example Playground https://playground.babylonjs.com/#L49EJ7#68

#### Parameters

• ##### alpha: number

defines the rotation around first axis

• ##### beta: number

defines the rotation around second axis

• ##### gamma: number

defines the rotation around third axis

#### Returns Quaternion

the new quaternion

• RotationAlphaBetaGammaToRef<T>(alpha: number, beta: number, gamma: number, result: T): T
• Creates a new quaternion from the given Euler float angles expressed in z-x-z orientation and stores it in the target quaternion Example Playground https://playground.babylonjs.com/#L49EJ7#69

#### Parameters

• ##### alpha: number

defines the rotation around first axis

• ##### beta: number

defines the rotation around second axis

• ##### gamma: number

defines the rotation around third axis

• ##### result: T

defines the target quaternion

#### Returns T

result input

• Creates a quaternion from a rotation around an axis Example Playground https://playground.babylonjs.com/#L49EJ7#72

#### Parameters

• ##### axis: DeepImmutableObject<Vector3>

defines the axis to use

• ##### angle: number

defines the angle to use

#### Returns Quaternion

a new quaternion created from the given axis (Vector3) and angle in radians (float)

• Creates a rotation around an axis and stores it into the given quaternion Example Playground https://playground.babylonjs.com/#L49EJ7#73

#### Parameters

• ##### axis: DeepImmutableObject<Vector3>

defines the axis to use

• ##### angle: number

defines the angle to use

• ##### result: T

defines the target quaternion

#### Returns T

the target quaternion

• Creates a new quaternion containing the rotation value to reach the target (axis1, axis2, axis3) orientation as a rotated XYZ system (axis1, axis2 and axis3 are normalized during this operation) Example Playground https://playground.babylonjs.com/#L49EJ7#75

#### Parameters

• ##### axis1: DeepImmutableObject<Vector3>

defines the first axis

• ##### axis2: DeepImmutableObject<Vector3>

defines the second axis

• ##### axis3: DeepImmutableObject<Vector3>

defines the third axis

#### Returns Quaternion

the new quaternion

• Creates a rotation value to reach the target (axis1, axis2, axis3) orientation as a rotated XYZ system (axis1, axis2 and axis3 are normalized during this operation) and stores it in the target quaternion Example Playground https://playground.babylonjs.com/#L49EJ7#76

#### Parameters

• ##### axis1: DeepImmutableObject<Vector3>

defines the first axis

• ##### axis2: DeepImmutableObject<Vector3>

defines the second axis

• ##### axis3: DeepImmutableObject<Vector3>

defines the third axis

• ##### ref: T

defines the target quaternion

#### Returns T

result input

• RotationYawPitchRoll(yaw: number, pitch: number, roll: number): Quaternion
• Creates a new quaternion from the given Euler float angles (y, x, z) Example Playground https://playground.babylonjs.com/#L49EJ7#77

#### Parameters

• ##### yaw: number

defines the rotation around Y axis

• ##### pitch: number

defines the rotation around X axis

• ##### roll: number

defines the rotation around Z axis

#### Returns Quaternion

the new quaternion

• RotationYawPitchRollToRef<T>(yaw: number, pitch: number, roll: number, result: T): T
• Creates a new rotation from the given Euler float angles (y, x, z) and stores it in the target quaternion Example Playground https://playground.babylonjs.com/#L49EJ7#78

#### Parameters

• ##### yaw: number

defines the rotation around Y axis

• ##### pitch: number

defines the rotation around X axis

• ##### roll: number

defines the rotation around Z axis

• ##### result: T

defines the target quaternion

#### Returns T

result input

• Interpolates between two quaternions Example Playground https://playground.babylonjs.com/#L49EJ7#79

#### Parameters

• ##### left: DeepImmutableObject<Quaternion>

defines first quaternion

• ##### right: DeepImmutableObject<Quaternion>

defines second quaternion

#### Returns Quaternion

the new interpolated quaternion

• Interpolates between two quaternions and stores it into a target quaternion Example Playground https://playground.babylonjs.com/#L49EJ7#92

#### Parameters

• ##### left: DeepImmutableObject<Quaternion>

defines first quaternion

• ##### right: DeepImmutableObject<Quaternion>

defines second quaternion

• ##### result: T

defines the target quaternion

#### Returns T

result input

• SmoothToRef<T>(source: Quaternion, goal: Quaternion, deltaTime: number, lerpTime: number, result: T): T
• Smooth interpolation between two quaternions using Slerp Example Playground https://playground.babylonjs.com/#L49EJ7#93

#### Parameters

• ##### source: Quaternion

source quaternion

• ##### goal: Quaternion

goal quaternion

• ##### deltaTime: number

current interpolation frame

• ##### lerpTime: number

total interpolation time

• ##### result: T

the smoothed quaternion

#### Returns T

• Creates an empty quaternion

#### Returns Quaternion

a new quaternion set to (0.0, 0.0, 0.0)

## Legend

• Constructor
• Property
• Method
• Accessor
• Inherited constructor
• Inherited property
• Inherited method
• Property
• Method
• Static method

Theme