Quaternion & Euler Rotations
# Quaternions
expressed as 4 numbers vector4 = [x, y, z, w]
It’s usually used to define rotational transformation in 3D Space. To do so it needs 2 types of information:
- rotational angle $\theta$
- rotational axis $A$
The 4 vector values of a quaternion are calculated in the following way:
$q = (sin(\frac{\theta}{2})*Ax, sin(\frac{\theta}{2})*Ay, sin(\frac{\theta}{2})*Az, cos(\frac{\theta}{2}))$
In VEX we can use the quaternion function which accepts an angle in radians and an axis vector to propagate the vector4 accordingly.
# Rotating Vectors
|
|
# Euler Rotation
While Quaternians define the rotational transformation with an angle around a specified axis, Euler rotation is defined by 3 Parameters (compare Transform Node
x, y, z).
To convert Euler rotations to quaternions we need to specify the rotation order:
|
|
Rotation Order Integer Arguments as defined in $HH/vex/include/math.h
:
|
|
Same thing works backwards:
|
|
# Blending Quaternions with slerp()
Matrices can do most of what quaternions can do and more (translation & scale). However, one thing that quaternions enable you to do is using the slerp
function to blend smoothly between two rotational transformations.
In this example the two orientations get initialized buy rotating a line in two different ways and extracting each quaternion.
|
|
Then we can blend rotationally between the two orientations with the slerp
function and apply the blended result.
|
|
Download: File
# Using dihedral
Function to Orient Vectors
The dihedral function creates a quaternion that describes the rotational transformation between two given vectors. This can be used to switch between two orientations of a mesh.
|
|
# sources / further reading
- [VEX for Algorithmic Design] E14 _ Quaternion Basics - Junichiro Horikawa
- Visualizing quaternions - Grant Sanderson (3blue1brown)