Posts

Showing posts with the label Math

Derivative of quaternion

Image
When I was searching for uses of quaternions in orientation algorithms, there was always one equation that was shown with no explanation:  \begin{gather}\dot{\mathbf{q}}(t)=\frac{1}{2}\boldsymbol{\omega}\mathbf{q}(t) \end{gather} but sometimes it was: \begin{gather}\dot{\mathbf{q}}(t)=-\frac{1}{2}\boldsymbol{\omega}\mathbf{q}(t) \end{gather} or \begin{gather}\dot{\mathbf{q}}(t)=-\frac{1}{2}\mathbf{q}(t) \boldsymbol{\omega}\end{gather} Moreover, when I was looking for any derivation of these formulas I found out that all resources were several pages - not very encouraging for me or derivations were not complete in their own calculations, which was even more frustrating when you were thinking that finally, you would understand this.  So, I decided to do it myself in 2 ways: first more based on quaternion interpretation and the second old-fashion derivative from the definition. Also, I will discuss frames of reference in which all of the elements are presented. I will provide some transfo

Quaternions as rotations in 3D

Just as a unit circle in the complex plane can be used to describe a rotation in one axis, quaternions using 3 imaginary numbers describe a rotation in 3 dimensions. According to Euler's rotation theorem , any complex rotation of any vector $\mathbf{p}\in \mathbb{R}^3$ about any axes can be replaced by a single rotation about the $\mathbf{v}=[v_x,v_y,v_z] $ by an angle $\theta$. Using quaternions, the rotation of a vector $\mathbf{p}$ can be represented by multiplication: \begin{equation}\mathbf{p}'=\mathbf{q}\mathbf{p}\mathbf{q}^{-1}=\mathbf{q}\mathbf{p}\mathbf{q}^*\label{eq:rotation}\end{equation} where vector $\mathbf{p}$ is treated as a pure quaternion - $\mathbf{p}= [0,p_x,p_y,p_z]$, and quaternion $\mathbf{q}$ in trygonmetric form is: \begin{equation}    \mathbf{q}=\cos{\frac{\theta}{2}}+[v_xi,v_yj,v_zk]\sin{\frac{\theta}{2}}\label{eq:trigonometric form written out}\end{equation} It can now be seen that the imaginary part of the quaternion can be treated as the vector def

Quaternions introduction

 Why quaternions? The quaternion notation is the least intuitive solution, but it has several advantages that make it very commonly used in many fields that deal with orientation in 3D space. First, however, the basic operations in the domain of quaternions as well as the assumptions made in the following chapters will be described. The main advantages will be seen in the next chapters, but this part is to give some awareness about quaternions properties used in the next operations. Although it is not necessary to understand quaternions up smallest detail, in my opinion, it is really pleasant to know how some mathematics, used in projects works. Also, I hope that this presentation of quaternions (of course not complete and probably fully correct in math rigor) will be more approachable for non-mathematicians. What are quaternions? Quaternions are just extensions of complex numbers.They have Real part - $Re(\mathbf{q})$ and Imaginary part - $Im(\mathbf{q})$ but instead of 1, there are 3

LERP, NLERP and SLERP

Image
WHAT IS THAT AND WHY DO YOU NEED THIS? Whenever you've got 2 numbers and you want something between them, you want some kind of interpolation. And the same in quaternions - you have to quaternions that describe the same no one is 100% correct but 100% incorrect either, so you want a quaternion that is a combination of these two. So you can use the simplest idea of combining two numbers: \[\mathbf{q}_{3}=\alpha \mathbf{q}_{1} +(1-\alpha)\mathbf{q}_{2} \label{eq:LERP}\] this is LERP ( linear interpolation ) but since, for orientation porpuse quaternion need to have norm of 1, after this interpolation you need to normalize result: \[\mathbf{q}_{3}=norm(\alpha \mathbf{q}_{1} +(1-\alpha)\mathbf{q}_{2}) \label{eq:NLERP}\] and that is NLERP ( normalized linear interpolation ) . Now, how these methods could be interpreted, and what are the consequences in real applications?  If we imagine a circle with a radius of 1 which is going across quaternions that we want to interpolat