2 minute read

3. 3D Rigid Body Motion (2)

3.4 Quaternion

앞서 소개한 Euler Angle의 문제점을 보완할 도구로 Quaternion(사원수) 체계가 있다.

quaternion은 3개의 imaginary + 1개의 scalar으로 이루어져 있다.

\[\mathbf{q}=q_{0}+q_{1} i+q_{2} j+q_{3} k\]

혹은 다음과 같이 표현한다

\[\mathbf{q}=[s, \mathbf{v}]^{\mathrm{T}}, \quad s=q_{0} \in \mathbb{R}, \quad \mathbf{v}=\left[q_{1}, q_{2}, q_{3}\right]^{\mathrm{T}} \in \mathbb{R}^{3}\]

그리고 아래와 같은 성질이 있다.

\[\left\{\begin{array}{l}i^{2}=j^{2}=k^{2}=-1 \\i j=k, j i=-k \\j k=i, k j=-i \\k i=j, i k=-j\end{array}\right.\]

imaginary 부분이 0인 경우를 real quaternion,

scalar 부분이 0인 경우를 imaginary quaternion이라고 하며

크기가 1인 quaternion을 unit quaternion이라고 한다.

3.4.1 Quaternion Operations

  1. 덧셈 뺄셈
\[\mathbf{q}=[s, \mathbf{v}]^{\mathrm{T}}, \quad s=q_{0} \in \mathbb{R}, \quad \mathbf{v}=\left[q_{1}, q_{2}, q_{3}\right]^{\mathrm{T}} \in \mathbb{R}^{3}\]
  1. 곱셈
\[\begin{aligned}\mathbf{q}_{a} \mathbf{q}_{b} &=s_{a} s_{b}-x_{a} x_{b}-y_{a} y_{b}-z_{a} z_{b} \\&+\left(s_{a} x_{b}+x_{a} s_{b}+y_{a} z_{b}-z_{a} y_{b}\right) i \\&+\left(s_{a} y_{b}-x_{a} z_{b}+y_{a} s_{b}+z_{a} x_{b}\right) j \\&+\left(s_{a} z_{b}+x_{a} y_{b}-y_{a} x_{b}+z_{a} s_{b}\right) k\end{aligned}\] \[\mathbf{q}_{a} \mathbf{q}_{b}=\left[s_{a} s_{b}-\mathbf{v}_{a}^{\mathrm{T}} \mathbf{v}_{b}, s_{a} \mathbf{v}_{b}+s_{b} \mathbf{v}_{a}+\mathbf{v}_{a} \times \mathbf{v}_{b}\right]^{\mathrm{T}}\]
  1. 길이
\[\left\|\mathbf{q}_{a}\right\|=\sqrt{s_{a}^{2}+x_{a}^{2}+y_{a}^{2}+z_{a}^{2}}\]
  1. 켤레 복소수 (Cojugate)
\[\mathbf{q}_{a}^{*}=s_{a}-x_{a} i-y_{a} j-z_{a} k=\left[s_{a},-\mathbf{v}_{a}\right]^{\mathrm{T}}\]
  1. 역(Inverse)
\[\mathbf{q}^{-1}=\mathbf{q}^{*} /\|\mathbf{q}\|^{2}\]

여기서 quaternion과 그의 역의 곱셈은

\[\mathbf{q} \mathbf{q}^{-1}=\mathbf{q}^{-1} \mathbf{q}=\mathbf{1}\]

그리고 quaternion이 unit quaternion인 경우 inverse와 conjugate가 같다 따라서

\[\left(\mathbf{q}_{a} \mathbf{q}_{b}\right)^{-1}=\mathbf{q}_{b}^{-1} \mathbf{q}_{a}^{-1}\]

행렬과 비슷

  1. 스칼라 곱
\[k \mathbf{q}=[k s, k \mathbf{v}]^{\mathrm{T}}\]

3.4.2 Use Quaternion to Represent Rotation

\[\mathbf{p}^{\prime}=\mathbf{R} \mathbf{p}\]

\(\textbf{p}\) 에서 \(\textbf{p}'\) 로 회전한 상태를 행렬로 표현한 것이다.

이를 quaternion을 이용하여 표현한다면,

\[s \mathbf{p}=[0, x, y, z]^{\mathrm{T}}=[0, \mathbf{v}]^{\mathrm{T}}\] \[\mathbf{p}^{\prime}=\mathbf{q p q}^{-1}\]

\(\textbf{p}'\) 와 \(\textbf{p}\) 는 imaginary quaterion이다

3.4.3 Conversion of Quaternions to other Rotation Representations

Quaternion과 Rotation간의 관계를 알고 싶다.

우선 다음과 같은 다음과 같은 quaternion matrix 4x4를 정의하자

\[\mathbf{q}=[s, \mathbf{v}]^{\mathrm{T}}\]

일 때

다음과 같이 정의한다

\[\mathbf{q}^{+}=\left[\begin{array}{cc}s & -\mathbf{v}^{\mathrm{T}} \\\mathbf{v} & s \mathbf{I}+\mathbf{v}^{\wedge}\end{array}\right], \quad \mathbf{q}^{\oplus}=\left[\begin{array}{cc}s & -\mathbf{v}^{\mathrm{T}} \\\mathbf{v} & s \mathbf{I}-\mathbf{v}^{\wedge}\end{array}\right]\]

이는 quaternion을 4x4 matrix로 바꾼 것이다 (마치 skew-symmetric matrix 처럼)

그러면 다음이 성립한다.

\[\mathbf{q}_{1}^{+} \mathbf{q}_{2}=\left[\begin{array}{cc}s_{1} & -\mathbf{v}_{1}^{T} \\\mathbf{v}_{1} & s_{1} \mathbf{I}+\mathbf{v}_{1}^{\wedge}\end{array}\right]\left[\begin{array}{c}s_{2} \\\mathbf{v}_{2}\end{array}\right]=\left[\begin{array}{c}-\mathbf{v}_{1}^{T} \mathbf{v}_{2}+s_{1} s_{2} \\s_{1} \mathbf{v}_{2}+s_{2} \mathbf{v}_{1}+\mathbf{v}_{1}^{\wedge} \mathbf{v}_{2}\end{array}\right]=\mathbf{q}_{1} \mathbf{q}_{2}\] \[\mathbf{q}_{1} \mathbf{q}_{2}=\mathbf{q}_{1}^{+} \mathbf{q}_{2}=\mathbf{q}_{2}^{\oplus} \mathbf{q}_{1}\]

quaternion matrix를 이용하여 quaternion의 곱셈을 수행할 수 있다.

그러면 이전에 봤던 식에 적용해보면

\[\begin{aligned}\mathbf{p}^{\prime} &=\mathbf{q} \mathbf{p} \mathbf{q}^{-1}=\mathbf{q}^{+} \mathbf{p}^{+} \mathbf{q}^{-1} \\&=\mathbf{q}^{+} \mathbf{q}^{-1^{\oplus}} \mathbf{p} .\end{aligned}\] \[\mathbf{q}^{+}\left(\mathbf{q}^{-1}\right)^{\oplus}=\left[\begin{array}{cc}s & -\mathbf{v}^{T} \\\mathbf{v} & s \mathbf{I}+\mathbf{v}^{\wedge}\end{array}\right]\left[\begin{array}{cc}s & \mathbf{v}^{T} \\-\mathbf{v} & s \mathbf{I}+\mathbf{v}^{\wedge}\end{array}\right]=\left[\begin{array}{cc}1 & \mathbf{0} \\\mathbf{0}^{\mathrm{T}} & \mathbf{v} \mathbf{v}^{\mathrm{T}}+s^{2} \mathbf{I}+2 s \mathbf{v}^{\wedge}+\left(\mathbf{v}^{\wedge}\right)^{2}\end{array}\right]\]

\(\textbf{p}'\) 와 \(\textbf{p}\) 는 imaginary quaterion이므로 오른쪽 아래의 행렬은

quaternion에서 rotation matrix로 변환해주는 transformation을 나타낸다

\[\mathbf{R}=\mathbf{v} \mathbf{v}^{\mathrm{T}}+s^{2} \mathbf{I}+2 s \mathbf{v}^{\wedge}+\left(\mathbf{v}^{\wedge}\right)^{2}\]

회전 각도도 구할 수 있다

\[\begin{aligned}\operatorname{tr}(\mathbf{R}) &=\operatorname{tr}\left(\mathbf{v} \mathbf{v}^{\mathrm{T}}\right)+3 s^{2}+2 s \cdot 0+\operatorname{tr}\left(\left(\mathbf{v}^{\wedge}\right)^{2}\right) \\&=v_{1}^{2}+v_{2}^{2}+v_{3}^{2}+3 s^{2}-2\left(v_{1}^{2}+v_{2}^{2}+v_{3}^{2}\right) \\&=\left(1-s^{2}\right)+3 s^{2}-2\left(1-s^{2}\right) \\&=4 s^{2}-1\end{aligned}\] \[\begin{array}{c}\theta=\arccos \left(\cfrac{\operatorname{tr}(\mathbf{R})-1}{2}\right) \\=\arccos \left(2 s^{2}-1\right) \\\cos \theta=2 s^{2}-1=2 \cos ^{2} \cfrac{\theta}{2}-1 \\\theta=2 \arccos s\end{array}\]

\(\textbf{q}\) 의 imaginary part는 회전하는 동안 움직이지 않는다 (회전 축) 따라서 normalize 시켜준다

\[\left\{\begin{array}{l}\theta=2 \arccos q_{0} \\{\left[n_{x}, n_{y}, n_{z}\right]^{\mathrm{T}}=\left[q_{1}, q_{2}, q_{3}\right]^{\mathrm{T}} / \sin \frac{\theta}{2}}\end{array}\right.\]

3.5 Affine and Projective Transformation

다른 변환도 잠깐 살펴보자

Untitled

Updated: