How to calculate sin/cos/tan of a Quaternion?

2.9k Views Asked by At

I would like to learn about Quaternions. I've read this article: https://en.wikipedia.org/wiki/Quaternion

Most of the article was not hard to understand, except the (Exponential, logarithm, and power) part.

To calculate the exponential, I have to calculate sin/cos of the imaginary part, but that functions aren't defined on Quaternions (in the article).

3

There are 3 best solutions below

0
On BEST ANSWER

As you can see in the answer cited in the comment, the exponential of a quaternion $z=a+b\mathbf{i}+c\mathbf{j}+d\mathbf{k} = a+\mathbf{v}$, is:

$$ e^z = e^{a+\mathbf{v}}=e^a \left( \cos |\mathbf{v}| +\dfrac{\mathbf{v}}{|\mathbf{v}|} \,\sin |\mathbf{v}| \right) $$

where $|\mathbf v|= \sqrt{b^2+c^2+d^2}$ is a real number (the modulus of $\mathbf v$), so $\cos |\mathbf{v}|$ and $ \sin |\mathbf{v}|$ are well known trigonometric function of a real number, and they have nothing to do with $\cos$ and $\sin$ of a quaternion.

Such ''trigonometric function'' of a quaternion can be defined using a series expansion, in an analogous way than the exponential function because also these series are absolutely convergent, but non commutativity of quaternions gives some troubles about the properties of such functions.

0
On

We can define the sine, cosine, tangent and co. via the associated series expansions.

But before we derive anything, we first have to define something: Let's say that a quaternion $q$ of the general form $\mathbb{H} \ni q \equiv w + x \cdot i + y \cdot j + z \cdot k \wedge \left\{ w,\, x,\, y,\, z \right\} \in \mathbb{R}$, where $i,\, j,\, k$ are the classical imaginary units. With this we can split each quaternion into a scarlar part $\mathrm{s}$ and a vector part $\mathrm{v}$: $q = \mathrm{s} + \mathrm{v}$ - where $\mathrm{s} = w$ and $\mathrm{v} = x \cdot i + y \cdot j + z \cdot k$.

Since the series expansions I'm going to use are all power series, we can do a little bit and look at the general powers of the scalar part: $$ \begin{align*} \mathrm{v}^{2} &= \left( x \cdot i + y \cdot j + z \cdot k \right)^{2}\\ \mathrm{v}^{2} &= -x^{2} - y^{2} - z^{2}\\ \mathrm{v}^{2} &= -\left( x^{2} + y^{2} + z^{2} \right)\\ \mathrm{v}^{2} &= -\left( \sqrt{x^{2} + y^{2} + z^{2}} \right)^{2}\\ \mathrm{v}^{2} &= -\left| x^{2} + y^{2} + z^{2} \right|^{2}\\ \mathrm{v}^{2} &= -\left| \mathrm{v} \right|^{2}\\ \end{align*} $$

So when $n \in \mathbb{N}$: $$ \begin{align*} \mathrm{v}^{2 \cdot n} &= \left( \mathrm{v}^{2} \right)^{n}\\ \mathrm{v}^{2 \cdot n} &= \left( -\left| \mathrm{v} \right|^{2} \right)^{n} \cdot \mathrm{v}\\ \mathrm{v}^{2 \cdot n} &= \left( -1 \right)^{n} \cdot \left( \left| \mathrm{v} \right|^{2} \right)^{n} \cdot \mathrm{v}\\ \mathrm{v}^{2 \cdot n} &= \left( -1 \right)^{n} \cdot \left| \mathrm{v} \right|^{2 \cdot n}\\ \\ \mathrm{v}^{2 \cdot n + 1} &= \left( \mathrm{v}^{2} \right)^{n} \cdot \mathrm{v}\\ \mathrm{v}^{2 \cdot n + 1} &= \left( \mathrm{v}^{2} \right)^{n} \cdot \mathrm{v}\\ \mathrm{v}^{2 \cdot n + 1} &= \left( -\left| \mathrm{v} \right|^{2} \right)^{n} \cdot \mathrm{v}\\ \mathrm{v}^{2 \cdot n + 1} &= \left( -1 \right)^{n} \cdot \left( \left| \mathrm{v} \right|^{2} \right)^{n} \cdot \mathrm{v}\\ \mathrm{v}^{2 \cdot n + 1} &= \left( -1 \right)^{n} \cdot \left| \mathrm{v} \right|^{2 \cdot n} \cdot \mathrm{v}\\ \end{align*} $$


Sine And Cosine

According to the addition theorems of sine and cosine we get: $$ \begin{align*} \sin\left( \mathrm{s} + \mathrm{v} \right) &= \cos\left( \mathrm{v} \right) \cdot \sin\left( \mathrm{s} \right) + \cos\left( \mathrm{s} \right) \cdot \sin\left( \mathrm{v} \right)\\ \cos\left( \mathrm{s} + \mathrm{v} \right) &= \cos\left( \mathrm{s} \right) \cdot \cos\left( \mathrm{v} \right) + \sin\left( \mathrm{s} \right) \cdot \sin\left( \mathrm{v} \right)\\ \end{align*} $$

This means that the scalar part and the vector part have been separated and you can now work with the series expansions:

Sine

$$ \begin{align*} \sin\left( \mathrm{v} \right) &\equiv \sum\limits_{k = 0}^{\infty}\left[ \frac{\left( -1 \right)^{k}}{\left( 2 \cdot k + 1 \right)!} \cdot \mathrm{v}^{2 \cdot k + 1} \right]\\ \sin\left( \mathrm{v} \right) &\equiv \sum\limits_{k = 0}^{\infty}\left[ \frac{\left( -1 \right)^{k}}{\left( 2 \cdot k + 1 \right)!} \cdot \left( -1 \right)^{k} \cdot \left| \mathrm{v} \right|^{2 \cdot k} \cdot \mathrm{v} \right]\\ \sin\left( \mathrm{v} \right) &\equiv \sum\limits_{k = 0}^{\infty}\left[ \frac{\left( -1 \right)^{2 \cdot k}}{\left( 2 \cdot k + 1 \right)!} \cdot \left| \mathrm{v} \right|^{2 \cdot k} \cdot \mathrm{v} \right]\\ \sin\left( \mathrm{v} \right) &\equiv \sum\limits_{k = 0}^{\infty}\left[ \frac{\left( \left( -1 \right)^{2} \right)^{k}}{\left( 2 \cdot k + 1 \right)!} \cdot \left| \mathrm{v} \right|^{2 \cdot k} \cdot \mathrm{v} \right]\\ \sin\left( \mathrm{v} \right) &\equiv \sum\limits_{k = 0}^{\infty}\left[ \frac{\left( 1 \right)^{k}}{\left( 2 \cdot k + 1 \right)!} \cdot \left| \mathrm{v} \right|^{2 \cdot k} \cdot \mathrm{v} \right]\\ \sin\left( \mathrm{v} \right) &\equiv \sum\limits_{k = 0}^{\infty}\left[ \frac{1}{\left( 2 \cdot k + 1 \right)!} \cdot \left| \mathrm{v} \right|^{2 \cdot k} \cdot \mathrm{v} \right]\\ \sin\left( \mathrm{v} \right) &\equiv \sum\limits_{k = 0}^{\infty}\left[ \frac{1}{\left( 2 \cdot k + 1 \right)!} \cdot \left| \mathrm{v} \right|^{2 \cdot k} \right] \cdot \mathrm{v}\\ \sin\left( \mathrm{v} \right) &\equiv \sum\limits_{k = 0}^{\infty}\left[ \frac{1}{\left( 2 \cdot k + 1 \right)!} \cdot \left| \mathrm{v} \right|^{2 \cdot k + 1} \right] \cdot \frac{\mathrm{v}}{\left| \mathrm{v} \right|}\\ \sin\left( \mathrm{v} \right) &\equiv \sinh\left( \left| \mathrm{v} \right| \right) \cdot \frac{\mathrm{v}}{\left| \mathrm{v} \right|}\\ \end{align*} $$

Cosine

$$ \begin{align*} \cos\left( \mathrm{v} \right) &\equiv \sum\limits_{k = 0}^{\infty}\left[ \frac{\left( -1 \right)^{k}}{\left( 2 \cdot k\right)!} \cdot \mathrm{v}^{2 \cdot k} \right]\\ \cos\left( \mathrm{v} \right) &\equiv \sum\limits_{k = 0}^{\infty}\left[ \frac{\left( -1 \right)^{k}}{\left( 2 \cdot k\right)!} \cdot \left( -1 \right)^{k} \cdot \left| \mathrm{v} \right|^{2 \cdot k} \right]\\ \cos\left( \mathrm{v} \right) &\equiv \sum\limits_{k = 0}^{\infty}\left[ \frac{\left( -1 \right)^{2 \cdot k}}{\left( 2 \cdot k\right)!} \cdot \left| \mathrm{v} \right|^{2 \cdot k} \right]\\ \cos\left( \mathrm{v} \right) &\equiv \sum\limits_{k = 0}^{\infty}\left[ \frac{\left( \left( -1 \right)^{2} \right)^{k}}{\left( 2 \cdot k\right)!} \cdot \left| \mathrm{v} \right|^{2 \cdot k} \right]\\ \cos\left( \mathrm{v} \right) &\equiv \sum\limits_{k = 0}^{\infty}\left[ \frac{\left( 1 \right)^{k}}{\left( 2 \cdot k\right)!} \cdot \left| \mathrm{v} \right|^{2 \cdot k} \right]\\ \cos\left( \mathrm{v} \right) &\equiv \sum\limits_{k = 0}^{\infty}\left[ \frac{1}{\left( 2 \cdot k\right)!} \cdot \left| \mathrm{v} \right|^{2 \cdot k} \right]\\ \cos\left( \mathrm{v} \right) &\equiv \cosh\left( \left| \mathrm{v} \right| \right)\\ \end{align*} $$

General

$$\fbox{$ \begin{align*} \sin\left( q \right) &= \cosh\left( \left| \mathrm{v} \right| \right) \cdot \sin\left( \mathrm{s} \right) + \cos\left( \mathrm{s} \right) \cdot \sinh\left( \left| \mathrm{v} \right| \right) \cdot \frac{\mathrm{v}}{\left| \mathrm{v} \right|}\\ \cos\left( q \right) &= \cos\left( \mathrm{s} \right) \cdot \cosh\left( \left| \mathrm{v} \right| \right) + \sin\left( \mathrm{s} \right) \cdot \sinh\left( \left| \mathrm{v} \right| \right) \cdot \frac{\mathrm{v}}{\left| \mathrm{v} \right|}\\ \end{align*} $} \tag{1}$$

$$\fbox{$ \begin{align*} \sin\left( q \right) &= \cosh\left( \left| \sqrt{x^{2} + y^{2} + z^{2}} \right| \right) \cdot \sin\left( w \right) + \cos\left( w \right) \cdot \sinh\left( \sqrt{x^{2} + y^{2} + z^{2}} \right) \cdot \frac{x \cdot i + y \cdot j + z \cdot k}{\sqrt{x^{2} + y^{2} + z^{2}}}\\ \cos\left( q \right) &= \cos\left( w \right) \cdot \cosh\left( \sqrt{x^{2} + y^{2} + z^{2}} \right) + \sin\left( w \right) \cdot \sinh\left( \sqrt{x^{2} + y^{2} + z^{2}} \right) \cdot \frac{x \cdot i + y \cdot j + z \cdot k}{\sqrt{x^{2} + y^{2} + z^{2}}}\\ \end{align*} $} \tag{1}$$

Tangent And Cotangent

We know the definition of the tangent $\tan\left( q \right) \equiv \frac{\sin\left( q \right)}{\cos\left( q \right)}$ and the cotangent $\cot\left( q \right) \equiv \frac{\cos\left( q \right)}{\sin\left( q \right)}$. So we can just use our well derived formulas to solve. For that we first have to look at division with quaternions: $$ \begin{align*} \frac{q_{1}}{q_{2}} &= \frac{\mathrm{s}_{1} + \mathrm{v}_{1}}{\mathrm{s}_{2} + \mathrm{v}_{2}}\\ \frac{q_{1}}{q_{2}} &= \frac{\left( \mathrm{s}_{1} + \mathrm{v}_{1} \right) \cdot \left( \mathrm{s}_{2} + \overline{\mathrm{v}_{2}} \right)}{\left( \mathrm{s}_{2} + \mathrm{v}_{2} \right) \cdot \left( \mathrm{s}_{2} + \overline{\mathrm{v}_{2}} \right)}\\ \frac{q_{1}}{q_{2}} &= \frac{\left( \mathrm{s}_{1} + \mathrm{v}_{1} \right) \cdot \left( \mathrm{s}_{2} + \overline{\mathrm{v}_{2}} \right)}{\left| \mathrm{s}_{2} + \mathrm{v}_{2} \right|^{2}}\\ \frac{q_{1}}{q_{2}} &= \frac{\left( \mathrm{s}_{1} + \mathrm{v}_{1} \right) \cdot \left( \mathrm{s}_{2} - \mathrm{v}_{2} \right)}{\left| \mathrm{s}_{2} + \mathrm{v}_{2} \right|^{2}}\\ \end{align*} $$

So: $$\fbox{$ \begin{align*} \tan\left( q \right) &\equiv \frac{\left( \cosh\left( \left| \mathrm{v} \right| \right) \cdot \sin\left( \mathrm{s} \right) + \cos\left( \mathrm{s} \right) \cdot \sinh\left( \left| \mathrm{v} \right| \right) \cdot \frac{\mathrm{v}}{\left| \mathrm{v} \right|} \right) \cdot \left( \cos\left( \mathrm{s} \right) \cdot \cosh\left( \left| \mathrm{v} \right| \right) - \sin\left( \mathrm{s} \right) \cdot \sinh\left( \left| \mathrm{v} \right| \right) \cdot \frac{\mathrm{v}}{\left| \mathrm{v} \right|} \right)}{\left| \cos\left( \mathrm{s} \right) \cdot \cosh\left( \left| \mathrm{v} \right| \right) + \sin\left( \mathrm{s} \right) \cdot \sinh\left( \left| \mathrm{v} \right| \right) \cdot \frac{\mathrm{v}}{\left| \mathrm{v} \right|} \right|^{2}}\\ \cot\left( q \right) &\equiv \frac{\left( \cos\left( \mathrm{s} \right) \cdot \cosh\left( \left| \mathrm{v} \right| \right) + \sin\left( \mathrm{s} \right) \cdot \sinh\left( \left| \mathrm{v} \right| \right) \cdot \frac{\mathrm{v}}{\left| \mathrm{v} \right|} \right) \cdot \left( \cosh\left( \left| \mathrm{v} \right| \right) \cdot \sin\left( \mathrm{s} \right) - \cos\left( \mathrm{s} \right) \cdot \sinh\left( \left| \mathrm{v} \right| \right) \cdot \frac{\mathrm{v}}{\left| \mathrm{v} \right|} \right)}{\left| \cosh\left( \left| \mathrm{v} \right| \right) \cdot \sin\left( \mathrm{s} \right) + \cos\left( \mathrm{s} \right) \cdot \sinh\left( \left| \mathrm{v} \right| \right) \cdot \frac{\mathrm{v}}{\left| \mathrm{v} \right|} \right|^{2}}\\ \end{align*} $} \tag{2}$$

0
On

Given a quaternion q

To calculate exp(q) the trig functions of quaternions are not necessary.

But if you did want to find a trig function of q:

The first way is the Taylor series for said trig function. Even python can handle the first 15 digits in about 0.005 seconds for small values.

The second way is to use the polar form of the quaternion. First, we should start with trig of complex numbers:

cos(xi)=cosh(x)

sin(xi)=i sinh(x)

tan(xi)=i tanh(x)

so...

cos(a+bi) = cos(a) cosh(b) - i sin(a) sinh(b)

Expanding this for quaternions:

cos(xj)=cosh(x)

sin(xj)=j sinh(x)

tan(xj)=j tanh(x)

cos(xk)= cosh(x)

sin(xk)=k sinh(x)

tan(xk)=k tanh(x)

Polar form for quaternions uses three variables, which I will denote as r, p, and n.

q = a+bi+cd+dj = a+v = r(cos(p)+n sin(p))

r = abs(q) p = arccos(a/r) n = v/abs(v)

r is the distance from 0. p is the angle from 0 n is the direction of the angle

This is can be expanded for any versor (a quaternion q with abs(q) = 1) n with no real part:

cos(xn) = cosh(x)

sin(xn) = n cosh(x)

So the cosine can be gotten from the polar form of any quaternion: From a python quaternion-processing code I wrote:

    def __cos__(q, /):
        '''return cos of self in radians'''
        r, p, n = q.__polar__()
        return cos(q.real)*cosh(r*sin(p))-n*sin(q.real)*sinh(r*sin(p))

And in math-language:

a = r(cos(p)

cos(q)

= cos(r(cos(p)+n sin(p)))

= cos(a+n*sin(p))

= cos(a) cos(n r sin(p)) - sin(a) sin(n r sin(p))

= cos(a) cosh(r sin(p)) - n sin(a) sinh(r sin(p))

Python can process this in 0.00015 seconds.

Do the same for the rest of the trig functions to find them.

for cot, sec, and csc...

cot(xi) = coth(x)

sec(xi) = i*sech(x)

csc(ci) = i*csch(s)

and for hyperbolic trig,

cosh(xi) = cos(x)

sinh(xi) = i*sin(x)

tanh(xi) = i*tan(x)

coth(xi) = cot(x)

sech(xi) = i*sec(x)

csch(ci) = i*csc(s)