日本語 English

Quaternion

This page explains the quaternion functions of the calculation library for the OMRON NX/NJ series.
For the basic theory of quaternions, see Attitude Control (Euler Angles and Quaternions) .

Rotation of one point
Quaternion rotation axis

What Is a Quaternion?

A quaternion is a mathematical model for representing rotations in 3D space.
It is widely used in robot control, drone control, attitude control, 3D graphics and more. Euler angles can suffer from gimbal lock, but quaternions avoid that problem.

Examples of quaternion use

  • Calculating orientation in real time from the gyro in a phone
  • Rotations in games calculated by engines such as Unity and Unreal
  • Calculating the attitude control of a SpaceX rocket in real time
  • Robot control
  • Autonomous driving
  • AR (augmented reality)

Related pages

Quaternion operations

Quaternion creation (Quaternion)

Quaternion

Quaternion creation
Input
w
Scalar part (real part)
x
Vector part x (imaginary part)
y
Vector part y (imaginary part)
z
Vector part z (imaginary part)
Output
out
Quaternion

Example

Quaternion creation example
Input
w
1.0
x
2.0
y
3.0
z
4.0
Output
out
\[ \begin{bmatrix} q_w \\ q_x \\ q_y \\ q_z \\ \end{bmatrix} = \begin{bmatrix} 1 \\ 2 \\ 3 \\ 4 \\ \end{bmatrix} \]

Formulas

\begin{align} q=q_w+q_xi+q_yj+q_zk=& \begin{bmatrix} q_w \\ q_x \\ q_y \\ q_z \\ \end{bmatrix} \\ i^2+j^2+k^2=&-1 \\ ij=&k \\ jk=&i \\ ki=&j \end{align}


Comparison (qtEQ)

qtEQ

Quaternion comparison
Input
Q1
Quaternion 1
Q2
Quaternion 2

Example

Quaternion comparison example

Addition (qtADD)

qtADD

Quaternion addition
Input
Q1
Quaternion 1
Q2
Quaternion 2
Output
out
Quaternion

Example

Quaternion addition example
Input
Q1
[1.0, 1.0, 1.0, 1.0]
Q2
[0.5, 2.0, 1.0, 0.0]
Output
out
[1.5, 3.0, 2.0, 1.0]

Formulas

\[ Q1+Q2 = \begin{bmatrix} a_{w} \\ a_{x} \\ a_{y} \\ a_{z} \\ \end{bmatrix} + \begin{bmatrix} b_{w} \\ b_{x} \\ b_{y} \\ b_{z} \\ \end{bmatrix} = out \]


Subtraction (qtSUB)

qtSUB

Quaternion subtraction
Input
Q1
Quaternion 1
Q2
Quaternion 2
Output
out
Quaternion

Example

Quaternion subtraction example
Input
Q1
[1.0, 1.0, 1.0, 1.0]
Q2
[0.5, 2.0, 1.0, 0.0]
Output
out
[0.5, -1.0, 0.0, 1.0]

Formulas

\[ Q1-Q2 = \begin{bmatrix} a_{w} \\ a_{x} \\ a_{y} \\ a_{z} \\ \end{bmatrix} - \begin{bmatrix} b_{w} \\ b_{x} \\ b_{y} \\ b_{z} \\ \end{bmatrix} = out \]


Cross product (qtCross)

qtCross

Quaternion cross product
Input
Q1
Quaternion 1
Q2
Quaternion 2
Output
out
Quaternion

Example

Quaternion cross product example
Input
Q1
[1.0, 1.0, 1.0, 1.0]
Q2
[0.5, 2.0, 1.0, 0.0]
Output
out
[-2.5, 1.5, 3.5, -0.5]

Formulas

\[ Q1\times Q2 = \begin{bmatrix} a_{w} \\ a_{x} \\ a_{y} \\ a_{z} \\ \end{bmatrix} \times \begin{bmatrix} b_{w} \\ b_{x} \\ b_{y} \\ b_{z} \\ \end{bmatrix} = out \]


Conjugate (qtCQ)

qtCQ

Quaternion conjugate
Input
qt
Quaternion
Output
out
Quaternion

Example

Quaternion conjugate example
Input
qt
[0.5, 2.0, 1.0, 0.0]
Output
out
[0.5, -2.0, -1.0, -0.0]

Formulas

\[ \bar{qt} = \begin{bmatrix} a_{w} \\ a_{x} \\ a_{y} \\ a_{z} \\ \end{bmatrix} = out \]


Set real part (qtSetReal)

qtSetReal

Setting the quaternion real part
Input
w
Scalar part (real part)
In-out
qt
Quaternion

Example

Example of setting the quaternion real part
Input
w
0.5
In-out
qt
[0.5, 0.0, 0.0, 0.0]

Set imaginary part (qtSetImag)

qtSetImag

Setting the quaternion imaginary part
Input
vec
Vector part (imaginary part)
In-out
qt
Quaternion

Example

Example of setting the quaternion imaginary part
Input
vec
[1.0, 2.0, 3.0]
In-out
qt
[0.0, 1.0, 2.0, 3.0]

FAQ

What is a quaternion?

A mathematical model that expresses rotation with four components.

How does it differ from Euler angles?

No gimbal lock and smooth rotation interpolation are possible.

Are they used in robot control?

Widely used in industrial robots, drones and more.

Comments