quaternion
- Last UpdatedSep 17, 2025
- 2 minute read
This topic is about the quaternion data type.
Value syntax
quaternion q = {0,0.707,0,0.707};
Syntax notes
Previous assignment syntax can be used only during initialization. The following code will raise an error.
quaternion q;
q = {0,0.707,0,0.707};
After a quaternion is declared, it can be populated either by using the implemented API listed below or by assigning it the values from another quaternion.
quaternion q;
quaternion q2 = {0,0.707,0,0.707};
q = q2;
Description
Quaternion type is an array of four double values. It is used to host a quaternion representation of a transform rotation.
-
The default value is {0,0,0,0}.
-
The quaternion type partially supports arithmetic and comparison operators.
Autocasting
Quaternion type supports automatic conversion for
-
string, if in the correct input format (space separated list of four numbers); otherwise, it will raise an exception.
quaternion quat="0 0 0 1"; //quat={0,0,0,1};
-
vector4
vector4 v4={0,0.707,0,0.707};
quaternion quat=v4; //quat={0,0.707,0,0.707}
Properties
These are the properties for quaternion.
|
Property |
Return type |
Parameters |
Description |
|---|---|---|---|
|
x |
double |
|
Used to obtain first value from the quaternion. |
|
y |
double |
|
Used to obtain second value from the quaternion. |
|
z |
double |
|
Used to obtain third value from the quaternion. |
|
w |
double |
|
Used to obtain fourth value from the quaternion. |
Methods
This table shows the currently implemented methods.
|
Method |
Return type |
Parameters |
Description |
|---|---|---|---|
|
Lerp |
|
quaternion from, quaternion to, double t |
Linearly interpolates between from and to vectors by the interpolant t and returns the normalized result. |
|
Slerp |
|
quaternion from, quaternion to, double t, bool usesShortestPath |
Spherically interpolates between from and to vectors by the interpolant t and returns the normalized result. Parameter usesShortestPath is true by default, if not explicitly set, and causes the method to calculate the shortest rotation path between the from and to vectors. |
|
ToString |
string |
Returns a string that represents the current quaternion value. |