[Basic Type](../groups/Basic Type.Basic Type.md) / Quaternion
Quaternion Class
Quaternion
A unit quaternion used to represent 3D rotation.
Quaternions, similar to Transform, achieve a matrix representation of rotation. Unlike Transform, which stores rotations, scale, and cut, quaternions store only rotations.
Quaternions can be parameterized using axis angle pairs or Euler angles. Due to their compactness and the way they are stored in memory, some operations are more efficient for handling floating-point errors.
Table of contents
Properties
w: number |
---|
w weight. |
x: number |
x weight. |
y: number |
y weight. |
z: number |
z weight. |
halfToRad: any |
Obtain a half radian coefficient |
Accessors
conjugated(): Quaternion |
---|
Return the conjugate quaternion of the current quaternion, which is equivalent to finding the inverse of the unit quaternion but more efficient |
inverted(): Quaternion |
Return the inverse of the current quaternion |
length(): number |
Find the length of quaternions |
normalized(): Quaternion |
Return a new quaternion after normalizing the current quaternion |
sqrLength(): number |
Find the square of quaternion length |
identity(): Quaternion |
Get a unit quaternion |
Methods
clone(): Quaternion other |
---|
Clone the current quaternion. |
equals(a : Quaternion , b : Quaternion , epsilon? : number ): boolean other |
Approximate equivalence judgment of quaternions to exclude floating-point errors |
fromRotation(v : Rotation , outer? : Quaternion ): Quaternion other |
Read rotation angle data and create or write a quaternion |
getAxisX(outer? : Vector ): Vector other |
Returns the coordinate system X axis vector that defines this quaternion |
getAxisY(outer? : Vector ): Vector other |
Returns the Y axis vector of the coordinate system that defines this quaternion |
getAxisZ(outer? : Vector ): Vector other |
Return the Z-axis vector of the coordinate system that defines this quaternion |
getEuler(outerZ? : boolean , outer? : Vector ): Vector other |
Calculate Euler angles based on quaternions |
getEulerAngles(): Vector other |
Return the Euler angle (x-y-z) converted from the current quaternion. |
normalize(a : Quaternion , outer? : Quaternion ): Quaternion other |
Normalized Quaternion |
set(other ): Quaternion other |
Set the current quaternion to be equal to the specified quaternion. |
setEulerAngles(euler : Vector ): void other |
Set Euler angle |
strictEquals(a : Quaternion , b : Quaternion ): boolean other |
Quaternion equivalence judgment |
toRotation(): Rotation other |
Get the rotation data of a current quaternion |
toString(): string other |
Output as a string |
calculateW(a : Quaternion , outer? : Quaternion ): Quaternion other |
Calculate the w component based on the xyz component, which is normalized by default |
conjugate(a : Quaternion , outer? : Quaternion ): Quaternion other |
Finding conjugate quaternions is equivalent to finding the inverse of unit quaternions, but more efficient |
dot(a : Quaternion , b : Quaternion ): number other |
Quaternion point product (quantity product) |
equals(a : Quaternion , b : Quaternion , epsilon? : number ): boolean other |
Approximate equivalence judgment of quaternions to exclude floating-point errors |
fromAngleZ(z : number , outer? : Quaternion ): Quaternion other |
Calculate quaternions based on 2D angles (0,0,z) |
fromAxes(xAxis : Vector , yAxis : Vector , zAxis : Vector , outer? : Quaternion ): Quaternion other |
Calculate the quaternion according to the orientation of the coordinate axis. By default, the three vectors are normalized and vertical to each other |
fromAxisAngle(axis : Vector , rad : number , outer? : Quaternion ): Quaternion other |
Calculate quaternion based on rotation axis and rotation radian |
fromMatrix3x3(m : Matrix3x3 , outer? : Quaternion ): Quaternion other |
Calculate quaternions based on three-dimensional matrix information, assuming the input matrix does not contain scaling information |
fromRotation(v : Rotation , outer? : Quaternion ): Quaternion other |
Read rotation angle data and create or write a quaternion |
fromViewUp(view : Vector , up? : Vector , outer? : Quaternion ): Quaternion other |
Calculates quaternions based on the front and up directions of the viewport |
getAxis(q : Quaternion , outer? : Vector ): Vector other |
Obtain the rotation axis of quaternions |
getAxisAngle(q : Quaternion ): number other |
Obtain the rotation radius of quaternions |
invert(a : Quaternion , outer? : Quaternion ): Quaternion other |
Quaternion inversion |
lerp(a : Quaternion , b : Quaternion , t : number , outer? : Quaternion ): Quaternion other |
Element wise linear interpolation: A+t * (B - A) |
multiply(a : Quaternion , b : Quaternion , outer? : Quaternion ): Quaternion other |
Quaternion multiplication |
multiplyVector(a : Vector , q : Quaternion , outer? : Vector ): Vector other |
Multiplying a quaternion by a three-dimensional vector (usually used to rotate a vector through quaternions) |
normalize(a : Quaternion , outer? : Quaternion ): Quaternion other |
Normalized Quaternion |
rotateAround(rot : Quaternion , axis : Vector , rad : number , outer? : Quaternion ): Quaternion other |
Rotate quaternion around a specified axis in world space |
rotateAroundLocal(rot : Quaternion , axis : Vector , rad : number , outer? : Quaternion ): Quaternion other |
Rotate a quaternion around a specified axis in local space |
rotateX(a : Quaternion , rad : number , outer? : Quaternion ): Quaternion other |
Rotate around the X-axis to specify quaternions |
rotateY(a : Quaternion , rad : number , outer? : Quaternion ): Quaternion other |
Rotate the specified quaternion around the Y axis |
rotateZ(a : Quaternion , rad : number , outer? : Quaternion ): Quaternion other |
Rotate the specified quaternion about the Z axis |
rotationTo(a : Vector , b : Vector , outer? : Quaternion ): Quaternion other |
Set the quaternion as the shortest path rotation between two vectors a and b, with both vectors normalized by default |
slerp(a : Quaternion , b : Quaternion , t : number , outer? : Quaternion ): Quaternion other |
Quaternion spherical interpolation |
sqlerp(a : Quaternion , b : Quaternion , c : Quaternion , d : Quaternion , t : number , outer? : Quaternion ): Quaternion other |
Quaternion spherical interpolation with two control points |
strictEquals(a : Quaternion , b : Quaternion ): boolean other |
Quaternion equivalence judgment |
toMatrix3x3(q : Quaternion , outer? : Matrix3x3 ): Matrix3x3 other |
Calculate matrix based on quaternion rotation information |
• new Quaternion(v
)
Parameters
v Quaternion | Usage: Four Elements |
---|
• new Quaternion(x
, y
, z
, w
)
Parameters
x number | x Component default: 0 range: [-1,1] type: Floating point number |
---|---|
y number | y Component default: 0 range: [-1,1] type: Floating point number |
z number | z Component default: 0 range: [-1,1] type: Floating point number |
w number | w Component default: 1 range: [-1,1] type: Floating point number |
Properties
w
• w: number
w weight.
x
• x: number
x weight.
y
• y: number
y weight.
z
• z: number
z weight.
halfToRad
▪ Static
Private
halfToRad: any
Obtain a half radian coefficient
Accessors
conjugated
• | ||
---|---|---|
Return the conjugate quaternion of the current quaternion, which is equivalent to finding the inverse of the unit quaternion but more efficient Returns
|
inverted
• | ||
---|---|---|
Return the inverse of the current quaternion Returns
|
length
• | ||
---|---|---|
Find the length of quaternions Returns
|
normalized
• | ||
---|---|---|
Return a new quaternion after normalizing the current quaternion Returns
|
sqrLength
• | ||
---|---|---|
Find the square of quaternion length Returns
|
identity
• |
---|
Get a unit quaternion Precautions Quaternion(0,0,0,1)。 Returns |
Quaternion |
---|
Methods
clone
• clone(): Quaternion
other
Clone the current quaternion.
Returns
Quaternion | Quaternion |
---|
equals
• equals(other
, epsilon?
): boolean
other
Determine whether the current quaternion is equal to the specified vector within the error range.
Parameters
a Quaternion | Usage: Quaternion a |
---|---|
b Quaternion | Usage: Quaternion b |
epsilon? number | Usage: Minimum error default: 1. e-7 range: It is recommended to pass in a value less than 1. Type: Floating point number |
Returns
boolean | Return the result of whether it is equal or not |
---|
fromRotation
• fromRotation(v
): void
other
Read a rotation data from the current quaternion
Parameters
v Rotation | Usage: read string data |
---|---|
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
getAxisX
• getAxisX(outer?
): Vector
other
Returns the coordinate system X axis vector that defines this quaternion
Parameters
outer? Vector | Usage: Vector object for receiving results default: null |
---|
Returns
Vector | The X-axis vector of the coordinate system of this quaternion |
---|
getAxisY
• getAxisY(outer?
): Vector
other
Returns the Y axis vector of the coordinate system that defines this quaternion
Parameters
outer? Vector | Usage: Vector object for receiving results default: null |
---|
Returns
Vector | The Y-axis vector of the coordinate system of this quaternion |
---|
getAxisZ
• getAxisZ(outer?
): Vector
other
Return the Z-axis vector of the coordinate system that defines this quaternion
Parameters
outer? Vector | Usage: Vector object for receiving results default: null |
---|
Returns
Vector | The coordinate system Z axis vector of this quaternion |
---|
getEuler
• getEuler(outerZ?
, outer?
): Vector
other
Calculate Euler angles based on quaternions
Parameters
outerZ? boolean | Usage: Change the range of z values to [-180, -90] U [90180] default: false |
---|---|
outer? Vector | Usage: Vector object for receiving results default: null |
Returns
Vector | Euler's angle. The return angle x, y is within the range of [-180, 180], z default is within the range of [-90, 90], and the rotation order is YZX |
---|
getEulerAngles
• getEulerAngles(): Vector
other
Return the Euler angle (x-y-z) converted from the current quaternion.
Returns
Vector | Euler angle |
---|
normalize
• normalize(): void
other
Normalize the current quaternion
Parameters
a Quaternion | Usage: Quaternion a |
---|---|
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
set
• set(other
): Quaternion
other
Set the current quaternion to be equal to the specified quaternion.
Parameters
other Quaternion | Usage: Quaternion data |
---|
Returns
Quaternion | this |
---|
• set(x?
, y?
, z?
, w?
): Quaternion
other
Set the current quaternion to specify the element value.
Parameters
x? number | Usage: x-component of quaternion default: 0 range: [-1,1] type: floating-point number |
---|---|
y? number | Usage: y component of quaternion default: 0 range: [-1,1] type: floating-point number |
z? number | Usage: z component of quaternion default: 0 range: [-1,1] type: floating-point number |
w? number | Usage: w component of quaternion default: 0 range: [-1,1] type: floating-point number |
Returns
Quaternion | Current quaternion |
---|
setEulerAngles
• setEulerAngles(euler
): void
other
Set Euler angle
Parameters
euler Vector | Usage: Incoming Euler angles |
---|
strictEquals
• strictEquals(other
): boolean
other
Determine whether the current quaternion is equal to the specified quaternion.
Parameters
a Quaternion | Usage: Quaternion a |
---|---|
b Quaternion | Usage: Quaternion b |
Returns
boolean | Return the result of whether it is equal or not |
---|
toRotation
• toRotation(): Rotation
other
Get the rotation data of a current quaternion
Returns
Rotation | Rotating data |
---|
toString
• toString(): string
other
Output as a string
Returns
string | Quaternion numerical string |
---|
calculateW
• Static
calculateW(a
, outer?
): Quaternion
other
Calculate the w component based on the xyz component, which is normalized by default
Parameters
a Quaternion | Usage: Target Quaternion |
---|---|
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
conjugate
• Static
conjugate(a
, outer?
): Quaternion
other
Finding conjugate quaternions is equivalent to finding the inverse of unit quaternions, but more efficient
Parameters
a Quaternion | Usage: Quaternion a |
---|---|
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
dot
• Static
dot(a
, b
): number
other
Quaternion point product (quantity product)
Parameters
a Quaternion | Usage: Quaternion a |
---|---|
b Quaternion | Usage: Quaternion b |
Returns
number | Return a result count |
---|
equals
• Static
equals(a
, b
, epsilon?
): boolean
other
Approximate equivalence judgment of quaternions to exclude floating-point errors
Parameters
a Quaternion | Usage: Quaternion a |
---|---|
b Quaternion | Usage: Quaternion b |
epsilon? number | Usage: Minimum error default: 1. e-7 range: It is recommended to pass in a value less than 1. Type: Floating point number |
Returns
boolean | Return the result of whether it is equal or not |
---|
fromAngleZ
• Static
fromAngleZ(z
, outer?
): Quaternion
other
Calculate quaternions based on 2D angles (0,0,z)
Parameters
z number | Usage: The angle value of rotation around z< Range: unlimited type: floating point number |
---|---|
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
fromAxes
• Static
fromAxes(xAxis
, yAxis
, zAxis
, outer?
): Quaternion
other
Calculate the quaternion according to the orientation of the coordinate axis. By default, the three vectors are normalized and vertical to each other
Parameters
xAxis Vector | Usage: vector value of x axis |
---|---|
yAxis Vector | Usage: vector value of y axis |
zAxis Vector | Usage: vector value of z axis |
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
fromAxisAngle
• Static
fromAxisAngle(axis
, rad
, outer?
): Quaternion
other
Calculate quaternion based on rotation axis and rotation radian
Parameters
axis Vector | Usage: rotate axis |
---|---|
rad number | Usage: radian value range: unlimited type: floating-point number |
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
fromMatrix3x3
• Static
fromMatrix3x3(m
, outer?
): Quaternion
other
Calculate quaternions based on three-dimensional matrix information, assuming the input matrix does not contain scaling information
Parameters
m Matrix3x3 | Usage: 3D matrix |
---|---|
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
fromRotation
• Static
fromRotation(v
, outer?
): Quaternion
other
Read rotation angle data and create or write a quaternion
Parameters
v Rotation | Usage: read string data |
---|---|
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
fromViewUp
• Static
fromViewUp(view
, up?
, outer?
): Quaternion
other
Calculates quaternions based on the front and up directions of the viewport
Parameters
view Vector | Usage: front vector of viewport |
---|---|
up? Vector | Usage: upper vector default: null |
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
getAxis
• Static
getAxis(q
, outer?
): Vector
other
Obtain the rotation axis of quaternions
Parameters
q Quaternion | Usage: Target Quaternion |
---|---|
outer? Vector | Usage: Vector object written default: null |
Returns
Vector | Return a three-dimensional vector |
---|
getAxisAngle
• Static
getAxisAngle(q
): number
other
Obtain the rotation radius of quaternions
Parameters
q Quaternion | Usage: Target Quaternion |
---|
Returns
number | Return a radian value |
---|
invert
• Static
invert(a
, outer?
): Quaternion
other
Quaternion inversion
Parameters
a Quaternion | Usage: Quaternion a |
---|---|
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
lerp
• Static
lerp(a
, b
, t
, outer?
): Quaternion
other
Element wise linear interpolation: A+t * (B - A)
Parameters
a Quaternion | Usage: Quaternion a |
---|---|
b Quaternion | Usage: Quaternion b |
t number | Usage: Interpolation range: [0,1] type: Floating point number |
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
multiply
• Static
multiply(a
, b
, outer?
): Quaternion
other
Quaternion multiplication
Parameters
a Quaternion | Usage: Quaternion a |
---|---|
b Quaternion | Usage: Quaternion b |
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
multiplyVector
• Static
multiplyVector(a
, q
, outer?
): Vector
other
Multiplying a quaternion by a three-dimensional vector (usually used to rotate a vector through quaternions)
Parameters
a Vector | Usage: target vector |
---|---|
q Quaternion | Usage: Quaternion |
outer? Vector | Usage: Vector object written default: null |
Returns
Vector | Return a rotated 3D vector |
---|
normalize
• Static
normalize(a
, outer?
): Quaternion
other
Normalized Quaternion
Parameters
a Quaternion | Usage: Quaternion a |
---|---|
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
rotateAround
• Static
rotateAround(rot
, axis
, rad
, outer?
): Quaternion
other
Rotate quaternion around a specified axis in world space
Parameters
rot Quaternion | Usage: rotated quaternions |
---|---|
axis Vector | Usage: 3D vector representing the axis of rotation |
rad number | Usage: radian value range: unlimited type: floating-point number |
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
rotateAroundLocal
• Static
rotateAroundLocal(rot
, axis
, rad
, outer?
): Quaternion
other
Rotate a quaternion around a specified axis in local space
Parameters
rot Quaternion | Usage: Quaternions that need to be transformed |
---|---|
axis Vector | Usage: 3D vector representing the axis of rotation |
rad number | Usage: radian value range: unlimited type: floating-point number |
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
rotateX
• Static
rotateX(a
, rad
, outer?
): Quaternion
other
Rotate around the X-axis to specify quaternions
Parameters
a Quaternion | Usage: Quaternion |
---|---|
rad number | Usage: radian value range: unlimited type: floating-point number |
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
rotateY
• Static
rotateY(a
, rad
, outer?
): Quaternion
other
Rotate the specified quaternion around the Y axis
Parameters
a Quaternion | Usage: Quaternion |
---|---|
rad number | Usage: radian value range: unlimited type: floating-point number |
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
rotateZ
• Static
rotateZ(a
, rad
, outer?
): Quaternion
other
Rotate the specified quaternion about the Z axis
Parameters
a Quaternion | Usage: Quaternion |
---|---|
rad number | Usage: radian value range: unlimited type: floating-point number |
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
rotationTo
• Static
rotationTo(a
, b
, outer?
): Quaternion
other
Set the quaternion as the shortest path rotation between two vectors a and b, with both vectors normalized by default
Parameters
a Vector | Usage: vector a |
---|---|
b Vector | Usage: vector b |
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
slerp
• Static
slerp(a
, b
, t
, outer?
): Quaternion
other
Quaternion spherical interpolation
Parameters
a Quaternion | Usage: Quaternion a |
---|---|
b Quaternion | Usage: Quaternion b |
t number | Usage: Interpolation range: [0,1] type: Floating point number |
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
sqlerp
• Static
sqlerp(a
, b
, c
, d
, t
, outer?
): Quaternion
other
Quaternion spherical interpolation with two control points
Parameters
a Quaternion | Usage: Quaternion a |
---|---|
b Quaternion | Usage: Quaternion b |
c Quaternion | Usage: Quaternion c |
d Quaternion | Usage: Quaternion d |
t number | Usage: Interpolation range: [0,1] type: Floating point number |
outer? Quaternion | Usage: Quaternion object for receiving results default: null |
Returns
Quaternion | Return a quaternion |
---|
strictEquals
• Static
strictEquals(a
, b
): boolean
other
Quaternion equivalence judgment
Parameters
a Quaternion | Usage: Quaternion a |
---|---|
b Quaternion | Usage: Quaternion b |
Returns
boolean | Return the result of whether it is equal or not |
---|
toMatrix3x3
• Static
toMatrix3x3(q
, outer?
): Matrix3x3
other
Calculate matrix based on quaternion rotation information
Parameters
q Quaternion | Usage: Quaternion information |
---|---|
outer? Matrix3x3 | Usage: Matrix3x3 object written default: null |
Returns
Matrix3x3 | Return a three-dimensional matrix |
---|