Header menu logo Euclid

Quaternion Type

An immutable unitized Quaternion, for arbitrary 3D rotations. This implementation guarantees the Quaternion to be always unitized. Note: Never use the struct default constructor Quaternion() as it will create an invalid zero length Quaternion. Use Quaternion.create or Quaternion.createUnchecked instead.

Record fields

Record Field Description

W

Full Usage: W

Field type: float

The W component of this Quaternion.

Field type: float

X

Full Usage: X

Field type: float

The X component of this Quaternion.

Field type: float

Y

Full Usage: Y

Field type: float

The Y component of this Quaternion.

Field type: float

Z

Full Usage: Z

Field type: float

The Z component of this Quaternion.

Field type: float

Instance members

Instance member Description

this.AngleInDegrees

Full Usage: this.AngleInDegrees

Returns: float
Modifiers: inline

Returns the angle in Degree.

Returns: float

this.AngleInRadians

Full Usage: this.AngleInRadians

Returns: float
Modifiers: inline

Returns the angle in Radians.

Returns: float

this.Axis

Full Usage: this.Axis

Returns: Vec
Modifiers: inline

Returns the rotation axis of this Quaternion. This is just q.X, q.Y and q.Z. The length of this vector is less than one.

Returns: Vec

this.Conjugate

Full Usage: this.Conjugate

Returns: Quaternion
Modifiers: inline

Returns a new Quaternion for the inverse rotation. Same as q.Inverse.

Returns: Quaternion

this.Inverse

Full Usage: this.Inverse

Returns: Quaternion
Modifiers: inline

Returns a new Quaternion for the inverse rotation. Same as q.Conjugate.

Returns: Quaternion

this.setAngleInDegrees angleInDegrees

Full Usage: this.setAngleInDegrees angleInDegrees

Parameters:
    angleInDegrees : float

Returns: Quaternion
Modifiers: inline

Get a new Quaternion that rotates around the same axis but with the different angle. In Degree.

angleInDegrees : float
Returns: Quaternion

this.setAngleInRadians angleInRadians

Full Usage: this.setAngleInRadians angleInRadians

Parameters:
    angleInRadians : float

Returns: Quaternion

Get a new Quaternion that rotates around the same axis but with the different angle. In Radians.

angleInRadians : float
Returns: Quaternion

Static members

Static member Description

p *** q

Full Usage: p *** q

Parameters:
Returns: Pnt
Modifiers: inline

Rotate by Quaternion around Origin. Multiplies (or applies) a Quaternion to a 3D point.

p : Pnt
q : Quaternion
Returns: Pnt

v *** q

Full Usage: v *** q

Parameters:
Returns: UnitVec
Modifiers: inline

Rotate by Quaternion around Origin. Multiplies (or applies) a Quaternion to a 3D unit-vector.

v : UnitVec
q : Quaternion
Returns: UnitVec

v *** q

Full Usage: v *** q

Parameters:
Returns: Vec
Modifiers: inline

Rotate by Quaternion around Origin. Multiplies (or applies) a Quaternion to a 3D vector.

v : Vec
q : Quaternion
Returns: Vec

l *** r

Full Usage: l *** r

Parameters:
Returns: Quaternion
Modifiers: inline

Multiply two Quaternions. Its like adding one rotation to the other.

l : Quaternion
r : Quaternion
Returns: Quaternion

Quaternion.create (x, y, z, w)

Full Usage: Quaternion.create (x, y, z, w)

Parameters:
    x : float
    y : float
    z : float
    w : float

Returns: Quaternion

This constructor does unitizing too.

x : float
y : float
z : float
w : float
Returns: Quaternion

Quaternion.createDirectlyUnchecked (x, y, z, w)

Full Usage: Quaternion.createDirectlyUnchecked (x, y, z, w)

Parameters:
    x : float
    y : float
    z : float
    w : float

Returns: Quaternion
Modifiers: inline

This unsafe constructor does do any unitizing.

x : float
y : float
z : float
w : float
Returns: Quaternion

Quaternion.createFromDegree (axis, angleInDegrees)

Full Usage: Quaternion.createFromDegree (axis, angleInDegrees)

Parameters:
    axis : UnitVec
    angleInDegrees : float

Returns: Quaternion
Modifiers: inline

The created rotation is Clockwise looking in the direction of the unit-vector.

axis : UnitVec
angleInDegrees : float
Returns: Quaternion

Quaternion.createFromDegree (axis, angleInDegrees)

Full Usage: Quaternion.createFromDegree (axis, angleInDegrees)

Parameters:
    axis : Vec
    angleInDegrees : float

Returns: Quaternion
Modifiers: inline

The created rotation is Clockwise looking in the direction of the vector (of any length but zero).

axis : Vec
angleInDegrees : float
Returns: Quaternion

Quaternion.createFromEulerXYZ (degreesX, degreesY, degreesZ)

Full Usage: Quaternion.createFromEulerXYZ (degreesX, degreesY, degreesZ)

Parameters:
    degreesX : float
    degreesY : float
    degreesZ : float

Returns: Quaternion

Angles are given in Degrees, The order in which to apply rotations is X-Y-Z, which means that the object will first be rotated around its X-axis, then its Y-axis and finally its Z-axis. This uses intrinsic Tait-Bryan angles. This means that rotations are performed with respect to the local coordinate system. That is, for order X-Y-Z, the rotation is first around the local-X-axis (which is the same as the World-X-axis), then around local-Y (which may now be different from the World Y-axis), then local-Z (which may be different from the World Z-axis)

degreesX : float
degreesY : float
degreesZ : float
Returns: Quaternion

Quaternion.createFromEulerXZY (degreesX, degreesZ, degreesY)

Full Usage: Quaternion.createFromEulerXZY (degreesX, degreesZ, degreesY)

Parameters:
    degreesX : float
    degreesZ : float
    degreesY : float

Returns: Quaternion

Angles are given in Degrees, The order in which to apply rotations is X-Z-Y, which means that the object will first be rotated around its X-axis, then its Z-axis and finally its Y-axis. This uses intrinsic Tait-Bryan angles. This means that rotations are performed with respect to the local coordinate system. That is, for order X-Z-Y, the rotation is first around the local-X-axis (which is the same as the World-X-axis), then around local-Z (which may now be different from the World Z-axis), then local-Y (which may be different from the World Y-axis)

degreesX : float
degreesZ : float
degreesY : float
Returns: Quaternion

Quaternion.createFromEulerYXZ (degreesY, degreesX, degreesZ)

Full Usage: Quaternion.createFromEulerYXZ (degreesY, degreesX, degreesZ)

Parameters:
    degreesY : float
    degreesX : float
    degreesZ : float

Returns: Quaternion

Angles are given in Degrees, The order in which to apply rotations is Y-X-Z, which means that the object will first be rotated around its Y-axis, then its X-axis and finally its Z-axis. This uses intrinsic Tait-Bryan angles. This means that rotations are performed with respect to the local coordinate system. That is, for order Y-X-Z, the rotation is first around the local-Y-axis (which is the same as the World-Y-axis), then around local-X (which may now be different from the World X-axis), then local-Z (which may be different from the World Z-axis)

degreesY : float
degreesX : float
degreesZ : float
Returns: Quaternion

Quaternion.createFromEulerYZX (degreesY, degreesZ, degreesX)

Full Usage: Quaternion.createFromEulerYZX (degreesY, degreesZ, degreesX)

Parameters:
    degreesY : float
    degreesZ : float
    degreesX : float

Returns: Quaternion

Angles are given in Degrees, The order in which to apply rotations is Y-Z-X, which means that the object will first be rotated around its Y-axis, then its Z-axis finally its X-axis. This uses intrinsic Tait-Bryan angles. This means that rotations are performed with respect to the local coordinate system. That is, for order Y-Z-X, the rotation is first around the local-Y-axis (which is the same as the World-Y-axis), then around local-Z (which may now be different from the World Z-axis), then local-X (which may be different from the World X-axis)

degreesY : float
degreesZ : float
degreesX : float
Returns: Quaternion

Quaternion.createFromEulerZXY (degreesZ, degreesX, degreesY)

Full Usage: Quaternion.createFromEulerZXY (degreesZ, degreesX, degreesY)

Parameters:
    degreesZ : float
    degreesX : float
    degreesY : float

Returns: Quaternion

Angles are given in Degrees, The order in which to apply rotations is Z-X-Y, which means that the object will first be rotated around its Z-axis, then its X-axis finally its Y-axis. This uses intrinsic Tait-Bryan angles. This means that rotations are performed with respect to the local coordinate system. That is, for order Z-X-Y, the rotation is first around the local-Z-axis (which is the same as the World-Z-axis), then around local-X (which may now be different from the World X-axis), then local-Y (which may be different from the World Y-axis)

degreesZ : float
degreesX : float
degreesY : float
Returns: Quaternion

Quaternion.createFromEulerZYX (degreesZ, degreesY, degreesX)

Full Usage: Quaternion.createFromEulerZYX (degreesZ, degreesY, degreesX)

Parameters:
    degreesZ : float
    degreesY : float
    degreesX : float

Returns: Quaternion

Angles are given in Degrees, The order in which to apply rotations is Z-Y-X, which means that the object will first be rotated around its Z-axis, then its Y-axis and finally its X-axis. This uses intrinsic Tait-Bryan angles. This means that rotations are performed with respect to the local coordinate system. That is, for order Z-Y-X, the rotation is first around the local Z-axis (which is the same as the World Z-axis), then around local-Y (which may now be different from the World Y-axis), then local-X (which may be different from the World X-axis)

degreesZ : float
degreesY : float
degreesX : float
Returns: Quaternion

Quaternion.createFromRadians (axis, angleInRadians)

Full Usage: Quaternion.createFromRadians (axis, angleInRadians)

Parameters:
    axis : UnitVec
    angleInRadians : float

Returns: Quaternion
Modifiers: inline

The created rotation is Clockwise looking in the direction of the unit-vector.

axis : UnitVec
angleInRadians : float
Returns: Quaternion

Quaternion.createFromRadians (axis, angleInRadians)

Full Usage: Quaternion.createFromRadians (axis, angleInRadians)

Parameters:
    axis : Vec
    angleInRadians : float

Returns: Quaternion

The created rotation is Clockwise looking in the direction of the vector. The vector may be of any length but zero.

axis : Vec
angleInRadians : float
Returns: Quaternion

Quaternion.createVecToVec (vecFrom, vecTo)

Full Usage: Quaternion.createVecToVec (vecFrom, vecTo)

Parameters:
Returns: Quaternion

Creates a rotation from one vectors direction to another vectors direction. If the tips of the two vectors unitized are closer than 1e-9 the identity Quaternion is returned. If the tips of the two vectors unitized are almost exactly opposite, deviating less than 1e-6 from line (unitized), there is no valid unique 180 degree rotation that can be found, so an exception is raised.

vecFrom : Vec
vecTo : Vec
Returns: Quaternion

Quaternion.createVecToVec (vecFrom, vecTo)

Full Usage: Quaternion.createVecToVec (vecFrom, vecTo)

Parameters:
Returns: Quaternion
Modifiers: inline

Creates a rotation from one vectors direction to another vectors direction. If the tips of the two vectors are closer than 1e-9 then an identity Quaternion is returned. If the tips of the two vectors are almost exactly opposite, deviating less than 1e-6 from line, there is no valid unique 180 degree rotation that can be found, so an exception is raised.

vecFrom : UnitVec
vecTo : UnitVec
Returns: Quaternion

Quaternion.identity

Full Usage: Quaternion.identity

Returns: Quaternion
Modifiers: inline

The identity quaternion that does not do any rotation. This is Quaternion(x=0, y=0, z=0, w=1)

Returns: Quaternion

Quaternion.multiply (l, r)

Full Usage: Quaternion.multiply (l, r)

Parameters:
Returns: Quaternion

Multiply two Quaternions. Its like adding one rotation to the other.

l : Quaternion
r : Quaternion
Returns: Quaternion

Quaternion.toEulerAnglesZYX q

Full Usage: Quaternion.toEulerAnglesZYX q

Parameters:
Returns: float * float * float

The quaternion expresses a relationship between two coordinate frames, A and B say. Returns the EulerAngles in Degrees: Alpha, Beta, Gamma. This relationship, if expressed using Euler angles, is as follows: 1) Rotate Frame A about its Z-axis by angle Gamma; 2) Rotate the resulting frame about its (new) Y-axis by angle Beta; 3) Rotate the resulting frame about its (new) X-axis by angle Alpha, to arrive at frame B. Returns the angels in Degrees as triple. For rotating first round the axis Z then local Y and finally local X. see Quaternion.createFromEulerZYX(z, y, x)

q : Quaternion
Returns: float * float * float

Type something to start searching.