<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>ComplexNumber on My Blog</title><link>https://EMEEEEMMMM.github.io/tags/complexnumber/</link><description>Recent content in ComplexNumber on My Blog</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sat, 23 May 2026 12:59:51 +0800</lastBuildDate><atom:link href="https://EMEEEEMMMM.github.io/tags/complexnumber/index.xml" rel="self" type="application/rss+xml"/><item><title>Quaternions</title><link>https://EMEEEEMMMM.github.io/posts/quaternion/</link><pubDate>Sat, 23 May 2026 12:59:51 +0800</pubDate><guid>https://EMEEEEMMMM.github.io/posts/quaternion/</guid><description>&lt;img src="https://EMEEEEMMMM.github.io/" alt="Featured image of post Quaternions" /&gt;&lt;h1 id="complex-number"&gt;Complex Number
&lt;/h1&gt;&lt;p&gt;We call the numbers of the form $a + bi$ complex numbers.
Set consisting of all complex numbers $\mathbb{C}={a+b \mathrm{i}\mid a,b \in \mathbb{R}}$, complex number is usually represented by letter $z$, so $z=a+b\mathrm{i}(a,b \in \mathbb{R})$ where $a$ is the real part of the number and $b$ is the imaginary part. A complex number is an imaginary number introduced on top of the real numbers in one dimension, forming a two dimensional complex plane. A particular complex number is a vector in that complex plane, as follows:
&lt;img alt="Complex_Vector" class="gallery-image" data-flex-basis="313px" data-flex-grow="130" height="521" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://EMEEEEMMMM.github.io/posts/quaternion/Complex_Vector.png" width="681"&gt;&lt;/p&gt;
&lt;h2 id="operations"&gt;Operations:
&lt;/h2&gt;&lt;h3 id="addition"&gt;Addition:
&lt;/h3&gt;&lt;p&gt;Two complex number $z_{1} = a+b\mathrm{i},\ z_{2} = c+d\mathrm{i} \ (a,b,c,d \in \mathbb{R})$ , their sum is:
&lt;/p&gt;
$$
z_{1} + z_{2} = (a+b\mathrm{i})+(c+d\mathrm{i})=(a+c) + (b+d)\mathrm{i}
$$&lt;p&gt;
For any complex number:
&lt;/p&gt;
$$
\begin{align}
z_{1} + z_{2} &amp;= z_{2} + z_{1} \\
(z_{1} + z_{2}) + z_{3} &amp;= z_{1} + (z_{2} + z_{3})
\end{align}
$$&lt;h3 id="subtraction"&gt;Subtraction:
&lt;/h3&gt;&lt;p&gt;Two complex number $z_{1} = a+b\mathrm{i},\ z_{2} = c+d\mathrm{i} \ (a,b,c,d \in \mathbb{R})$ , their difference is:
&lt;/p&gt;
$$
z_{1} - z_{2} = (a+b\mathrm{i})-(c+d\mathrm{i})=(a-c) + (b-d)\mathrm{i}
$$&lt;h3 id="multiplication"&gt;Multiplication:
&lt;/h3&gt;&lt;p&gt;Two complex number $z_{1} = a+b\mathrm{i},\ z_{2} = c+d\mathrm{i} \ (a,b,c,d \in \mathbb{R})$ , their product is:
&lt;/p&gt;
$$
\begin{align}
z_{1} \cdot z_{2} &amp;= (a+b\mathrm{i}) \cdot (c+d\mathrm{i}) \\
&amp;=ac+ad\mathrm{i}+bc\mathrm{i}+bd\mathrm{i}^2 \\
&amp;=(ac-bd) + (ad+bc)\mathrm{i}
\end{align}
$$&lt;p&gt;
For any complex number:
&lt;/p&gt;
$$
\begin{align}
z_{1} z_{2} &amp;= z_{2} z_{1} \\
(z_{1} z_{2}) z_{3} &amp;= z_{1} (z_{2} z_{3}) \\
z_{1} (z_{2} + z_{3}) &amp;= z_{1} z_{2} + z_{1} z_{3}
\end{align}
$$&lt;h3 id="division"&gt;Division:
&lt;/h3&gt;&lt;p&gt;Two complex number $z_{1} = a+b\mathrm{i},\ z_{2} = c+d\mathrm{i} \ (a,b,c,d \in \mathbb{R})$ , their quotient is:
&lt;/p&gt;
$$
\begin{align}
z_{1} \div z_{2} &amp;= \frac{a+b\mathrm{i}}{c+d\mathrm{i}} \\
&amp;= \frac{(a+b\mathrm{i}) (c-d\mathrm{i})}{(c+d\mathrm{i})(c-d\mathrm{i})} \\
&amp;= \frac{ac - ad\mathrm{i} + bc\mathrm{i} + bd}{c^2+d^2} \\
&amp;= \frac{ac+bd}{c^2+d^2} + \frac{bc-ad}{c^2+d^2}\mathrm{i}
\end{align}
$$&lt;h2 id="eulers-formula"&gt;Euler&amp;rsquo;s Formula:
&lt;/h2&gt;$$
e^{i \theta} = cos(\theta) + \mathrm{i} \sin(\theta) 
$$&lt;h3 id="proof"&gt;Proof:
&lt;/h3&gt;&lt;p&gt;The MacLaurin Series for $e^x$:
&lt;/p&gt;
$$
e^x=\sum_{n=0}^{\infty} \frac{x^n}{n!}=1+x+\frac{x^2}{2}+\frac{x^3}{6}+\cdots
$$&lt;p&gt;
For $e^{\mathrm{i} \theta}$, there exist:
&lt;/p&gt;
$$
\begin{align}
LHS = e^{\mathrm{i} \theta} &amp;= \sum_{n=0}^{\infty} \frac{(\mathrm{i} \theta)^n}{n!} \\
&amp;= 1 + \mathrm{i} \theta - \frac{\theta^2}{2!} + \frac{(\mathrm{i}\theta)^3}{3!} + \frac{\theta^4}{4!} + \cdots \\
&amp;= \left(1-\frac{\theta^2}{2!} + \frac{\theta^4}{4!} - \frac{\theta^6}{6!} + \cdots \right) + \mathrm{i} \left(\theta - \frac{\theta^3}{3!} + \frac{\theta^5}{5!} - \frac{\theta^7}{7!} + \cdots \right) \\
&amp;= \cos \theta + \mathrm{i} \sin \theta \\
&amp;= RHS
\end{align}
$$&lt;h2 id="the-derivation-for-formula-of-cos-ntheta-and-sin-ntheta"&gt;The derivation for formula of $\cos n\theta$ and $\sin n\theta$:
&lt;/h2&gt;$$
\begin{align}
\left(e^{\mathrm{i} \theta}\right)^{n} =e^{\mathrm{i}n\theta} &amp;= \cos n\theta + \mathrm{i} \sin n\theta \\
\left( \cos \theta + \mathrm{i} \sin \theta \right)^{n} &amp;= \cos n\theta + \mathrm{i} \sin n\theta \\
\cos n\theta + \mathrm{i} \sin n\theta &amp; = \sum_{k=0}^{n} \binom{n}{k} \left( \cos \theta \right)^{n-k} \left( \mathrm{i} \sin \theta \right)^k
\end{align}
$$&lt;p&gt;
Extract the real and imaginary parts of the expansion separately:
&lt;/p&gt;
$$
\begin{align}
\cos n\theta &amp;= \sum_{k=0}^{n} \binom{n}{2k} (\cos \theta)^{n-2k} (\mathrm{i} \sin \theta)^{2k} \\
&amp;= \sum_{k=0}^{n} \binom{n}{2k} (-1)^k (\cos \theta)^{n-2k} (\sin \theta)^{2k} \\
\mathrm{i} \sin n\theta &amp;= \sum_{k=0}^{n} \binom{n}{2k+1} (\cos \theta)^{n-2k-1} (\mathrm{i})^{2k+1} (\sin \theta)^{2k+1} \\
&amp;= \mathrm{i} \sum_{k=0}^{n} \binom{n}{2k+1} (\cos \theta)^{n-2k-1} (-1)^k (\sin \theta)^{2k+1} \\
\end{align}
$$&lt;p&gt;
&lt;/p&gt;
$$
\therefore \quad
\begin{cases}
\cos n\theta &amp;= \sum_{k=0}^{n} \binom{n}{2k} (-1)^k (\cos \theta)^{n-2k} (\sin \theta)^{2k} \\
\sin n\theta &amp;= \sum_{k=0}^{n} \binom{n}{2k+1}(-1)^k (\cos \theta)^{n-2k-1} (\sin \theta)^{2k+1} \\
\end{cases}
$$&lt;h3 id="chebyshev-polynomials"&gt;Chebyshev polynomials:
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;&lt;a class="link" href="https://zhuanlan.zhihu.com/p/55076525" target="_blank" rel="noopener"
 &gt;https://zhuanlan.zhihu.com/p/55076525&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id="quaternions"&gt;Quaternions
&lt;/h1&gt;&lt;p&gt;In complex numbers, the multiplication can represent the rotation in 2 dimensional space. For example, by rotating a vector $(a, bi)$ for $30 \degree$, just multiply it by $\cos 30 \degree + \mathrm{i} \sin 30 \degree$. But in three dimensional space, we need something that is stronger than complex numbers since that rotate about the x axis first and then rotate about the y axis is not equal to rotate about the y axis first and then rotate about the x axis, we need a algebraic system which does not satisfy commutative multiplication and is able to describe rotation in 3 dimensional space. So, the hypercomplex number, quaternions is just the right tool to use.&lt;/p&gt;
&lt;h2 id="definition"&gt;Definition:
&lt;/h2&gt;&lt;p&gt;The numbers in the form of:
&lt;/p&gt;
$$
q = a + b \mathrm{i} + c \mathrm{j} + d \mathrm{k} (a,b,c,d \in \mathbb{R})
$$&lt;h2 id="basic-properties"&gt;Basic properties:
&lt;/h2&gt;$$
\begin{align}
i^2 = j^2 = k^2 = -1 \\
ij = k, ji = -k, jk = i, kj = -i, ki = j, ik = -j
\end{align}
$$&lt;p&gt;For any quaternions, their conjugate is given by:
&lt;/p&gt;
$$
q = a - b \mathrm{i} - c \mathrm{j} - d \mathrm{k}
$$&lt;h2 id="operations-1"&gt;Operations:
&lt;/h2&gt;&lt;h3 id="addition-1"&gt;Addition:
&lt;/h3&gt;&lt;p&gt;For two quaternions $q = a + b \mathrm{i} + c \mathrm{j} + d \mathrm{k}$ and $p = t + x \mathrm{i} + y \mathrm{j} + z \mathrm{k}$, their sum is:
&lt;/p&gt;
$$
q+p = (a+t) + (b+x) \mathrm{i} + (c+y) \mathrm{j} + (d+z) \mathrm{k}
$$&lt;p&gt;
For any quaternions:
&lt;/p&gt;
$$
\begin{align}
q_{1} + q_{2} &amp;= q_{2} + q_{1} \\
(q_{1} + q_{2}) + q_{3} &amp;= q_{1} + (q_{2} + q_{3})
\end{align}
$$&lt;h3 id="subtraction-1"&gt;Subtraction:
&lt;/h3&gt;&lt;p&gt;For two quaternions $q = a + b \mathrm{i} + c \mathrm{j} + d \mathrm{k}$ and $p = t + x \mathrm{i} + y \mathrm{j} + z \mathrm{k}$, their difference is:
&lt;/p&gt;
$$
q-p = (a-t) + (b-x) \mathrm{i} + (c-y) \mathrm{j} + (d-z) \mathrm{k}
$$&lt;h3 id="multiplication-1"&gt;Multiplication:
&lt;/h3&gt;&lt;p&gt;For two quaternions $q = a + b \mathrm{i} + c \mathrm{j} + d \mathrm{k}$ and $p = t + x \mathrm{i} + y \mathrm{j} + z \mathrm{k}$, their product is:
&lt;/p&gt;
$$
\begin{align}
q \cdot p &amp;= (a + b \mathrm{i} + c \mathrm{j} + d \mathrm{k}) (t + x \mathrm{i} + y \mathrm{j} + z \mathrm{k}) \\
&amp;= at - bx - cy - dz \\
&amp;+ (ax+bt+cz-dy) \mathrm{i} \\
&amp;+ (ay-bz+ct+dx) \mathrm{j} \\
&amp;+ (az+by-cx+dt) \mathrm{k}
\end{align}
$$&lt;p&gt;Quaternions can also be expressed by a much simpler way:
$q = a + b \mathrm{i} + c \mathrm{j} + d \mathrm{k} = (a, \vec{a})$, where $\vec{a} = (b, c, d)$.
In this way, the multiplication would become:
&lt;/p&gt;
$$
\begin{align}
q \cdot p &amp;= (a + b \mathrm{i} + c \mathrm{j} + d \mathrm{k}) (t + x \mathrm{i} + y \mathrm{j} + z \mathrm{k}) \\
&amp;= (a, \vec{a}) (t, \vec{t}) \\
&amp;= (at - \vec{a} \cdot \vec{t}, a \vec{t} + t \vec{a} + \vec{a} \times \vec{t})
\end{align}
$$&lt;h2 id="rotation"&gt;Rotation:
&lt;/h2&gt;&lt;p&gt;We call the quaternions which have a zero real part the Pure Quaternions. For any vector in 3 dimensional space, we can plug it in a pure quaternion $q$:
&lt;/p&gt;
$$
q = (0, \vec{v}) = 0 + x \mathrm{i} + y \mathrm{j} + z \mathrm{k}
$$&lt;p&gt;
Let&amp;rsquo;s say that we are rotating about a unit vector $\hat{u}$ for $\theta$ angle. Imitate the way of the complex number where we multiply a $\cos \theta + \mathrm{i} \sin \theta$, we construct a similar quaternion:
&lt;/p&gt;
$$
q = (\cos \theta, \sin \theta \hat{u})
$$&lt;p&gt;
If we completely follow the steps of the rotation of the complex number, trying to multiply a pure quaternion:
&lt;/p&gt;
$$
\begin{align}
p \prime &amp;= (\cos \theta, \sin \theta \hat{u}) \cdot (0, \vec{v}) \\
&amp;= (0 - \sin \theta (\hat{u} \cdot \vec{v}), \cos \theta \vec{v} + \sin \theta (\hat{u} \times \vec{v}))
\end{align}
$$&lt;p&gt;
But the real part of this quaternion is not zero which means that unless $\hat{u} \cdot \vec{v} = 0$, the quaternion $p \prime$ won&amp;rsquo;t become a pure quaternion. This means that this equation is unable to handle most of the rotations in 3 dimensional space. We need to multiply another thing to cancel out the non-zero real part.&lt;/p&gt;
&lt;p&gt;Let $q$ be a unit quaternion, $v = (0, \vec{v})$ be a pure quaternion, $v\prime = (0, \vec{v}\prime)$ be the pure quaternion after the rotation. Expand and calculate:
&lt;/p&gt;
$$
\begin{align}
v\prime = qvq^{-1} &amp;= qvq^* \\
&amp;= (s_{q}, \vec{v_{q}}) \cdot (0, \vec{v}) \cdot (s_{q}, -\vec{v_{q}}) \\
&amp;= (- \vec{v_{q}} \cdot \vec{v}, s_{q} \vec{v} + \vec{v_{q}} \times \vec{v}) \cdot (s_{q}, -\vec{v_{q}}) \\
\mathrm{Re}(v\prime) &amp;= s_{q} \cdot (- \vec{v_{q}} \cdot \vec{v}) - (-\vec{v_{q}}) \cdot (s_q \vec{v} + \vec{v_{q}} \times \vec{v}) = 0 \\
\vec{v}\prime &amp;= (-\vec{v_q} \cdot \vec{v}) \cdot (-\vec{v_q}) + s_q \cdot (s_q \vec{v} + \vec{v_q} \times \vec{v}) + (s_q \vec{v} + \vec{v_q} \times \vec{v}) \times (-\vec{v_q}) \\
&amp;= (\vec{v_q} \vec{v}) \cdot \vec{v_q} + s_q^2 \vec{v} + s_q \cdot (\vec{v_q} \times \vec{v}) - s_q (\vec{v} \times \vec{v_q}) - (\vec{v_q} \times \vec{v}) \times \vec{v_q} \\
&amp;= (\vec{v_q} \vec{v}) \cdot \vec{v_q} + s_q^2 \vec{v} + s_q \cdot (\vec{v_q} \times \vec{v}) + s_q (\vec{v_q} \times \vec{v}) - (\vec{v_q} \cdot \vec{v_q}) \cdot \vec{v} + (\vec{v} \cdot \vec{v_q}) \cdot \vec{v_q} \\
&amp;= (s_q^2 - \lvert \lvert \vec{v_q} \rvert \rvert ^2) \vec{v} + 2 s_q (\vec{v_q} \times \vec{v}) + 2(\vec{v} \cdot \vec{v_q}) \cdot \vec{v_q}
\end{align}
$$&lt;p&gt;
So, the full expression for $v\prime$:
&lt;/p&gt;
$$
v\prime = qvq^{-1} = qvq^* = (0, (s_q^2 - \lvert \lvert \vec{v_q} \rvert \rvert ^2) \vec{v} + 2 s_q (\vec{v_q} \times \vec{v}) + 2(\vec{v} \cdot \vec{v_q}) \cdot \vec{v_q})
$$&lt;p&gt;
Now, we need to derive if $q$ express rotate about the rotation axis $u$ of $\theta$ degrees, what is the expression of $s_q$ and $v_q$.&lt;/p&gt;
&lt;p&gt;The imaginary part vector of a quaternion must be in the same direction with the rotation axis.
&lt;/p&gt;
$$
\vec{v_q} = k\vec{u} (k \in \mathbb{R})
$$&lt;p&gt;
Because of $q$ is a unit quaternion, there is $s_q^2 + \lvert\lvert v_q \rvert\rvert^2=s_q^2 + k^2=1$.
Now, we break down the vector $\vec{v}$ into two parts:
&lt;/p&gt;
$$
\vec{v} = \vec{v_{\lvert\lvert}} + \vec{v_\perp}
$$&lt;ul&gt;
&lt;li&gt;$\vec{v_{\lvert\lvert}}$ is collinear with $\vec{u}$, satisfying $\vec{v_{\lvert\lvert}} = (\vec{u}\cdot\vec{v})\cdot\vec{u}$.&lt;/li&gt;
&lt;li&gt;$\vec{v_\perp}$ is orthogonal to $\vec{u}$, meaning $\vec{u} \cdot \vec{v_\perp} = 0$.
First, sub $\vec{v_{\lvert\lvert}}$ into the expression of $\vec{v}\prime$:

$$
\begin{align}
\vec{v_{\lvert\lvert}}\prime &amp;= (s_q^2 - \lvert \lvert \vec{v_q} \rvert \rvert ^2) \vec{v_{\lvert\lvert}} + 2 s_q (\vec{v_q} \times \vec{v_{\lvert\lvert}}) + 2(\vec{v_{\lvert\lvert}} \cdot \vec{v_q}) \cdot \vec{v_q} \\
&amp;= (s_q^2 - k^2) \vec{v_{\lvert\lvert}} + 0 + 2k^2 \vec{v_{\lvert\lvert}} \\
&amp;= (s^2_q + k^2) \vec{v_{\lvert\lvert}} \\
&amp;= \vec{v_{\lvert\lvert}}
\end{align}
$$
This means that component which is parallel to the rotation axis remains completely undisturbed by the operation.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Second, sub $\vec{v_\perp}$ into the expression:
&lt;/p&gt;
$$
\begin{align}
\vec{v_\perp}\prime &amp;= (s_q^2 - \lvert \lvert \vec{v_q} \rvert \rvert ^2) \vec{v_\perp} + 2 s_q (\vec{v_q} \times \vec{v_\perp}) + 2(\vec{v_\perp} \cdot \vec{v_q}) \cdot \vec{v_q} \\
&amp;= (s_q^2 - k^2) \vec{v_\perp} + 2s_q(k \vec{u} \times \vec{v_\perp}) + 0 \\
&amp;= (s_q^2 - k^2) \vec{v_\perp} + 2s_q k (\vec{u} \times \vec{v}) 
\end{align}
$$&lt;p&gt;
Combines all these above together, the overall vector after the quaternion operation is:
&lt;/p&gt;
$$
\vec{v} \prime = \vec{v_{\lvert\lvert}} + (s_q^2 - k^2) \vec{v_\perp} + 2s_q k (\vec{u} \times \vec{v}) 
$$&lt;p&gt;
Now, we overlay the standard Rodrigues&amp;rsquo; Rotation Formula which dictates that a vector rotating around a unit axis $\vec{u}$ by a angle of $\theta$ behaves according to:
&lt;/p&gt;
$$
\vec{v} \prime = \vec{v_{\lvert\lvert}} + \cos \theta \vec{v_\perp} + \sin \theta (\vec{u} \times \vec{v})
$$&lt;p&gt;
By directly comparing the corresponding coefficients of our algebraic result against the geometric target:
&lt;/p&gt;
$$
\begin{cases}
s_q^2 - k^2 = \cos \theta \\
2s_qk = \sin \theta
\end{cases}
$$&lt;p&gt;
It is not hard to notice that the solution matches the standard trigonometric double-angle identities where:
&lt;/p&gt;
$$
\begin{align}
\cos \theta = \cos^2(\frac{\theta}{2}) - \sin^2(\frac{\theta}{2}) \\
\sin \theta = 2 \sin(\frac{\theta}{2}) \cos(\frac{\theta}{2})
\end{align}
$$&lt;p&gt;
Matching the terms explicitly yields the values for the scalar and vector scale factors of the quaternion:
&lt;/p&gt;
$$
s_q = \cos(\frac{\theta}{2}), k = \sin(\frac{\theta}{2})
$$&lt;p&gt;
So, substituting back these values into our initial definition $q = (s_q, \vec{v_q}) = (s_q, k \vec{u})$, we get the axis-angle rotation quaternion formula used universally in computer graphics and physics simulators:
&lt;/p&gt;
$$
q = \left[ \cos\left(\frac{\theta}{2}\right), \sin\left(\frac{\theta}{2}\right) \vec{u} \right]
$$&lt;h1 id="reference"&gt;Reference:
&lt;/h1&gt;&lt;ol&gt;
&lt;li&gt;[1] Yan-Bin Jia, Quaternions and Rotations. Com S 477/577 Course Notes, Iowa State University / Stanford Graphics Lab, 2013.
(&lt;a class="link" href="https://graphics.stanford.edu/courses/cs348a-17-winter/Papers/quaternion.pdf" target="_blank" rel="noopener"
 &gt;https://graphics.stanford.edu/courses/cs348a-17-winter/Papers/quaternion.pdf&lt;/a&gt;)&lt;/li&gt;
&lt;/ol&gt;</description></item></channel></rss>