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) .

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

- w
- Scalar part (real part)
- x
- Vector part x (imaginary part)
- y
- Vector part y (imaginary part)
- z
- Vector part z (imaginary part)
- out
- Quaternion
Example

- w
- 1.0
- x
- 2.0
- y
- 3.0
- z
- 4.0
- 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

- Q1
- Quaternion 1
- Q2
- Quaternion 2
Example
Addition (qtADD)
qtADD

- Q1
- Quaternion 1
- Q2
- Quaternion 2
- out
- Quaternion
Example

- Q1
- [1.0, 1.0, 1.0, 1.0]
- Q2
- [0.5, 2.0, 1.0, 0.0]
- 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

- Q1
- Quaternion 1
- Q2
- Quaternion 2
- out
- Quaternion
Example

- Q1
- [1.0, 1.0, 1.0, 1.0]
- Q2
- [0.5, 2.0, 1.0, 0.0]
- 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

- Q1
- Quaternion 1
- Q2
- Quaternion 2
- out
- Quaternion
Example

- Q1
- [1.0, 1.0, 1.0, 1.0]
- Q2
- [0.5, 2.0, 1.0, 0.0]
- 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

- qt
- Quaternion
- out
- Quaternion
Example

- qt
- [0.5, 2.0, 1.0, 0.0]
- 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

- w
- Scalar part (real part)
- qt
- Quaternion
Example

- w
- 0.5
- qt
- [0.5, 0.0, 0.0, 0.0]
Set imaginary part (qtSetImag)
qtSetImag

- vec
- Vector part (imaginary part)
- qt
- Quaternion
Example

- vec
- [1.0, 2.0, 3.0]
- 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.
