Derivation of Rotation Matrix

Rotation

Consider the situation where a point pp rotates around a normalized vector nˉ\bar{n} by α\alpha. Let pp' be the rotated point and rr be the intersection between nˉ\bar{n} and the plane where pp is rotating. As above, nˉ\bar{n} passes through (0,0,0)(0, 0, 0), Even though nˉ\bar{n} can be in any direction and pass any point, this vector can be translated so that it passes through (0,0,0)(0, 0, 0) keeping the direction. So, this assumption is still valid for simplicity. Now, the following equations are derived from the dot product and cross product. p=r+qq=qcosα+(nˉ×q)sinαr=(nˉp)nˉq=pr=p(nˉp)nˉ      nˉ×q=nˉ×(p(nˉp)nˉ)=nˉ×p      p=(nˉp)nˉ+(p(nˉp)nˉ)cosα+(nˉ×p)sinα\begin{aligned} &p' = r + q' \\ &q' = q \cos \alpha + (\bar{n} \times q) \sin \alpha \\ &r = (\bar{n} \cdot p) \bar{n}& \\ &q = p - r = p - (\bar{n} \cdot p) \bar{n} \\\\ \implies &\; \bar{n} \times q = \bar{n} \times (p - (\bar{n} \cdot p) \bar{n}) = \bar{n} \times p \\\\ \implies &\; p' = (\bar{n} \cdot p) \bar{n} + (p - (\bar{n} \cdot p) \bar{n}) \cos \alpha + (\bar{n} \times p) \sin \alpha \end{aligned}

Looking into the (nˉp)nˉ(\bar{n} \cdot p) \bar{n} part from the point of view of matrix form, (nˉp)nˉ=(nˉxpx+nˉypy+nˉzpz)(nˉxnˉynˉz)=(nˉx2px+nˉxnˉypy+nˉxnˉzpznˉxnˉypx+nˉy2py+nˉynˉzpznˉxnˉypx+nˉynˉzpy+nˉz2pz)=(nˉx2nˉxnˉynˉxnˉznˉxnˉynˉy2nˉynˉznˉxnˉynˉynˉznˉz2)(pxpypz)=(nˉxnˉynˉz)(nˉxnˉynˉz)p=(nˉ×nˉt)p\begin{aligned} (\bar{n} \cdot p) \bar{n} &= (\bar{n}_x p_x + \bar{n}_y p_y + \bar{n}_z p_z) \left(\begin{array}{c} \bar{n}_x \\ \bar{n}_y \\ \bar{n}_z \end{array}\right) = \left(\begin{array}{c} \bar{n}_x^2 p_x + \bar{n}_x \bar{n}_y p_y + \bar{n}_x \bar{n}_z p_z \\\\ \bar{n}_x \bar{n}_y p_x + \bar{n}_y^2 p_y + \bar{n}_y \bar{n}_z p_z \\\\ \bar{n}_x \bar{n}_y p_x + \bar{n}_y \bar{n}_z p_y + \bar{n}_z^2 p_z \end{array}\right) \\\\ &= \left(\begin{array}{ccc} \bar{n}_x^2 & \bar{n}_x \bar{n}_y & \bar{n}_x \bar{n}_z \\ \bar{n}_x \bar{n}_y & \bar{n}_y^2 & \bar{n}_y \bar{n}_z \\ \bar{n}_x \bar{n}_y & \bar{n}_y \bar{n}_z & \bar{n}_z^2 \end{array}\right) \left(\begin{array}{c} p_x \\ p_y \\ p_z \end{array}\right) = \left(\begin{array}{c} \bar{n}_x \\ \bar{n}_y \\ \bar{n}_z \end{array}\right) \left(\begin{array}{ccc} \bar{n}_x & \bar{n}_y & \bar{n}_z \end{array}\right) p = (\bar{n} \times \bar{n}^t) p \end{aligned}

As such, the (p(nˉp)nˉ)cosα(p - (\bar{n} \cdot p) \bar{n}) \cos \alpha part also can be rewritten as follows. (p(nˉp)nˉ)cosα=cosα(p(nˉ×nˉt)p)=cosα(Inˉ×nˉt)p\begin{aligned} (p - (\bar{n} \cdot p) \bar{n}) \cos \alpha = \cos \alpha (p - (\bar{n} \times \bar{n}^t) p) = \cos \alpha (I - \bar{n} \times \bar{n}^t) p \end{aligned}

The (nˉ×p)sinα(\bar{n} \times p) \sin \alpha part also can be reformed by skew-symmetric matrix. S=(0nˉznˉynˉz0nˉxnˉynˉx0)    (nˉ×p)sinα=sinαSp\begin{aligned} S = \left(\begin{array}{ccc} 0 & -\bar{n}_z & \bar{n}_y \\ \bar{n}_z & 0 & -\bar{n}_x \\ -\bar{n}_y & \bar{n}_x & 0 \end{array}\right) \implies (\bar{n} \times p) \sin \alpha = \sin \alpha S p \end{aligned}

Now, let R=nˉ×nˉt+cosα(Inˉ×nˉt)+sinαSR = \bar{n} \times \bar{n}^t + \cos \alpha (I - \bar{n} \times \bar{n}^t) + \sin \alpha S. Then p=Rpp' = Rp. Therefore, this RR is the rotation matrix. R=((1cosα)nˉx2+cosα(1cosα)nˉxnˉynˉzsinα(1cosα)nˉxnˉz+nˉysinα(1cosα)nˉxnˉy+nˉzsinα(1cosα)nˉy2+cosα(1cosα)nˉynˉznˉxsinα(1cosα)nˉxnˉznˉysinα(1cosα)nˉynˉz+nˉxsinα(1cosα)nˉz2+cosα)\begin{aligned} R = \left(\begin{array}{ccc} (1 - \cos \alpha) \bar{n}_x^2 + \cos \alpha & (1 - \cos \alpha) \bar{n}_x \bar{n}_y - \bar{n}_z \sin \alpha & (1 - \cos \alpha) \bar{n}_x \bar{n}_z + \bar{n}_y \sin \alpha \\\\ (1 - \cos \alpha) \bar{n}_x \bar{n}_y + \bar{n}_z \sin \alpha & (1 - \cos \alpha) \bar{n}_y^2 + \cos \alpha & (1 - \cos \alpha) \bar{n}_y \bar{n}_z - \bar{n}_x \sin \alpha \\\\ (1 - \cos \alpha) \bar{n}_x \bar{n}_z - \bar{n}_y \sin \alpha & (1 - \cos \alpha) \bar{n}_y \bar{n}_z + \bar{n}_x \sin \alpha & (1 - \cos \alpha) \bar{n}_z^2 + \cos \alpha \end{array}\right) \end{aligned}

Reference

[1] 3D Graphics Programming Using OpenGL: Introduction


© 2024. All rights reserved.