# Rotation

## 전체 글

(1)

### Rotation

Wanho Choi (wanochoi.com)

(2)

### Orthonormal Matrix

An×n = x| |1 x2 ⋯ x|n

| | |

xi : the i-th column vector of A (i : 1,2,⋯, n) xi ⋅ xj = {0 if i ≠ j1 if i = j AAT = (AT A)T = IT = I ATA = − x1− x2 − ⋮ − xn − | | | x1 x2 ⋯ xn | | | = x1 ⋅ x1 x1⋅ x2 ⋯ x1⋅ xn x2 ⋅ x1 x2⋅ x2 ⋯ x2⋅ xn ⋮ ⋮ ⋱ ⋮ xn ⋅ x1 xn⋅ x2 ⋯ xn⋅ xn = 1 0 ⋯ 0 0 1 ⋯ 0 ⋮ ⋮ ⋱ ⋮ 0 0 ⋯ 1 = I

(3)

T

T

−1

T

−1

T

−1

−1

T

T

2

(4)

### Rotation Matrix

• (rotation matrix) ⟺ (orthonormal matrix w/ det=1)

R = r11 r12 r13 r21 r22 r23 r31 r32 r33 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ RRT = RTR = I RT = R−1 det(R) = 1 ri ⋅rj = riTrj = 0 i

### (

≠ j & i, j = 0,1,2

1 i

### (

= j & i, j = 0,1,2

### )

⎧ ⎨ ⎪ ⎩⎪ R = | | | r0 r1 r2 | | | ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥

(5)

### Rotation Matrix

• (rotation matrix) ⟺ (orthonormal matrix w/ det=1)

• proof) Ax 2 = Ax( )T( )Ax = xTATAx = xT

### ( )

ATA x = xTIx = xTx = x 2 x+ y 2 = x + y( )T(x+ y)= xTx+ 2xTy+ yTy = x 2 + 2xTy+ y 2 similarly, A x( + y) 2 = Ax + Ay 2 = Ax + Ay( )T(Ax + Ay) = Ax 2 + 2 Ax( )T( )Ay + Ay 2 = x 2 + 2 Ax( )T Ay ( )+ y ∴ Ax 2 = x 2 ∴ Ax( )T Ay ( ) = xT y : angle preservation : length preservation

(6)

### Rotation Matrix

• (rotation matrix) ⟺ (orthonormal matrix w/ det=1)

• example)

det

([cosθ −sinθsinθ cosθ ]) = cos2θ + sin2θ = 1

det

(7)

Special Orthogonal group in 3D Euclidean spaceSpecial:Orthogonal:

### SO(3)

det(R) = 1 RRT = RTR = I

3×3

T

T

## }

1. R1, R2 ∈SO(3) ⇒ R1R2 ∈SO(3) R1R2

R1R2

### )

T = R1R2R2TR1T = R1R1T = I

det R

1R2

= det R

1 ⋅det R

### ( )

2 = 1 2. R ∈SO(3) ⇒ RT ∈SO(3)

3. R

1R2

R3 = R1

R2R3

### )

det(R) = −1: reflection

(8)

### The Column Vectors

(the i-th column vector): the i-th rotated axis

r11 r12 r13 r21 r22 r23 r31 r32 r33 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ 1 0 0 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ = r11 r21 r31 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ r11 r12 r13 r21 r22 r23 r31 r32 r33 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ 0 1 0 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ = r12 r22 r32 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ r11 r12 r13 r21 r22 r23 r31 r32 r33 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ = r13 r23 r33 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ R = r11 r12 r13 r21 r22 r23 r31 r32 r33 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ rotated z-axis rotated y-axis rotated x-axis

(9)

### Coordinate Rotation

• coordinate {A} ↔ coordinate {B}

xA, yA, zA

↔ x

B, yB, zB

### )

xA yA zA xB yB zB u v w xA 1 0 0 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ + yA 0 1 0 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ + zA 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ = xB ux uy uz ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ + yB vx vy vz ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ + zB wx wy wz ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⇔ 1 0 0 0 1 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ xA yA zA ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = ux vx wx uy vy wy uz vz wz ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ xB yB zB ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ xA yA zA ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = ux vx wx uy vy wy uz vz wz ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ xB yB zB ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ xB yB zB ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = ux uy uz vx vy vz wx wy wz ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ xA yA zA ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥

(10)

### Euler’s Rotation Theorem

• Any 3D rotation can be expressed as no more than

three rotations around coordinate axis, which is

equivalent to a single rotation about some axis that runs through the fixed point.

(11)

### Euler Angles

• The representation of a rotation as three consecutive axis rotations, three angles

Rz(α)= cosα −sinα 0 0 sinα cosα 0 0 0 0 1 0 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ Rx

α ⋅ Ry

β ⋅ Rz

γ Rx

α ⋅ Rz

γ ⋅ Ry

β Ry

β ⋅ Rx

α ⋅ Rz

γ Ry

β ⋅ Rz

γ ⋅ Rx

α Rz

γ ⋅ Rx

α ⋅ Ry

β Rz

γ ⋅ Ry

β ⋅ Rx

### ( )

α Rx(β)= 1 0 0 0 0 cosβ −sinβ 0 0 sinβ cosβ 0 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ Ry(γ )= cosγ 0 sinγ 0 0 1 0 0 −sinγ 0 cosγ 0 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥

(12)

### Euler Angles: Interpolation

• A rotation matrix cannot be component-wisely

interpolated! 1 2 0 0 1 0 1 0 −1 0 0 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ + 1 2 0 0 −1 0 1 0 1 0 0 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ = 0 0 0 0 1 0 0 0 0 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ rotation matrix (O) rotation matrix (O) rotation matrix (X)

(13)

### Euler Angles: Interpolation

• It is can be solved by interpolating angles individually.

But, the interpolation between two Euler angles is not

(14)
(15)

### Axis Angle (Rotational Axis)

• A rotation can be defined by a unit axis and an angle.

q = p0 + w = p0 + ucosθ + vsinθ

= p0 + p − p

0

cosθ + n × p

sinθ

= n⋅p

n + p − n⋅p

n

cosθ + n × p

### )

sinθ = pcosθ + n⋅p

n 1

− cosθ

+ n × p

### )

sinθ

θ p q o v u θ u w= Ru v r n p0 w p0 w= r cosθ r sinθ ⎡ ⎣ ⎢ ⎤ ⎦ ⎥ = r cosθ 0 ⎡ ⎣ ⎢ ⎤ ⎦ ⎥ +⎡ r sin0 θ ⎣ ⎢ ⎤ ⎦ ⎥ = r 0 ⎡ ⎣ ⎢ ⎤ ⎦ ⎥⋅cosθ + 0⎡ r ⎣ ⎢ ⎤ ⎦ ⎥⋅sinθ = ux uy ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥⋅cosθ + vx vy ⎡ ⎣ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥⋅sinθ = u⋅cosθ + v ⋅sinθ

(16)

### Axis Angle: Interpolation

a = p − o n = a × b a × b b = q − o p q o θ θ = cos−1 a ab b ⎛ ⎝⎜ ⎞ ⎠⎟ n rotation axis: rotation angle: r

q = pcosθ + n⋅p

n 1

− cosθ

+ n × p

sinθ

(17)

q = pcosθ + n⋅p

n 1

− cosθ

+ n × p

### )

sinθ

N≡ [n] = 0 −nz ny nz 0 −nx −ny nx 0 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⇔ n × p = Np N2= −ny 2− n z 2 nxny nznx nxny −nz2− n x 2 n ynz nznx nynz −nx2− n y 2 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = nx2−1 nxny nznx nxny ny2−1 n ynz nznx nynz nz2−1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = nx2 nxny nznx nxny ny2 n ynz nznx nynz nz2 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ − 1 0 0 0 1 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ = nnT− I ∵nx 2+ n y 2+ n z 2 = 1 ( ) n⋅p ( )n= nxpx+ nypy+ nzpz ( )nx nxpx+ nypy+ nzpz ( )ny nxpx+ nypy+ nzpz ( )nz ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ = nx2p x+ nxnypy+ nznxpz nxnypx+ ny 2 py+ nynzpz nznxpx+ nynzpy+ nz2pz ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = nx2 n xny nznx nxny ny 2 nynz nznx nynz nz2 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ px py pz ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = nn( )T p= N( 2+ I)p

∴q = pcosθ + (N2 + I)p 1− cos

θ

+ Np

### ( )

sinθ = Icos⎡⎣ θ + (N2 + I) 1− cos

θ

### )

+ Nsinθ ⎤⎦p = I + Nsin⎡⎣ θ + N2

1− cosθ

### )

⎤⎦p

= Rp R :rotation matrix

### )

R = I + Nsinθ + N2

1− cosθ

(18)

### Quaternion

• 4D complex number

• : unit vectors along three perpendicular Cartesian axes in 4D space

q = w + xˆi + yˆj + z ˆk (w, x, y, z) ∈!4

ˆi, ˆj, ˆk

ˆiˆj = ˆk = − ˆjˆi, ˆjˆk = ˆi = − ˆkˆj, ˆkˆi = ˆj = −ˆiˆk ˆi2 = ˆj2 = ˆk2 = −1, ˆiˆjˆk = −1

s = w: real part

v = (x, y,z): imaginary part

(19)

### Quaternion Operations

• Multiplication q1q2 = (s1 + v1)(s2 + v2) = w

### (

1 + x1ˆi + y1ˆj + z1ˆk

### (

w2 + x2ˆi + y2 ˆj + z2 ˆk

### )

= w( 1w2 − x1x2 − y1y2 − z1z2)+ w1

### (

w2 + x2ˆi + y2 ˆj + z2 ˆk

+ w2

### (

w1 + x1ˆi + y1ˆj + z1ˆk

### )

+ y( 1z2 − z1y2)ˆi + z( 1x2 − x1z2) ˆj + x( 1y2 − y1x2) ˆk = s( 1s2 − v1⋅v2)+ s( 1v2 + s2v1 + v1 × v2) q1 ± q2 = (s1 + v1)± (s2 + v2) = w( 1 ± w2)+ x( 1 ± x2)ˆi + y( 1 ± y2) ˆj + z( 1 ± z2) ˆk = (s1 ± s2)+ (v1 + v2) q1q2 ≠ q2q1 ( )

(20)

### Quaternion Operations

• Conjugate • Norm (magnitude) • Inverse q = s − v = w − xˆi − yˆj − z ˆk q = qq = s2 + v ⋅v = w2 + x2 + y2 + z2 q−1 = q q ∵ qq −1 = qq q = 1 ⎛ ⎝⎜ ⎞ ⎠⎟

(21)

### Unit Quaternion for Rotation

• Unit quaternion represents 3D rotation.

q = cos(θ / 2)+ usin(θ / 2) u = u1ˆi + u2ˆj + u3 ˆk u = u( 1,u2,u3) u = 1

q 2 = cos2(θ / 2)+ usin(θ / 2)⋅usin(θ / 2) = cos2(θ / 2)+ sin2(θ / 2) u 2 = 1

rotation angle: θ unit rotation axis: u

The same result as the rotation angle expression proof

(22)

### Example

qpq−1 = cosθ 2 + 0ˆi + 0 ˆj + sin θ 2 ˆk

⎝⎜ ⎞⎠⎟(0+ xˆi + yˆj + z ˆk) cosθ2 − 0ˆi − 0 ˆj − sin

θ 2 ˆk ⎛ ⎝⎜ ⎞⎠⎟ = cosθ 2 + 0ˆi + 0 ˆj + sin θ 2 ˆk ⎛ ⎝⎜ ⎞⎠⎟ z sinθ2 + (x cos θ 2 − ysin θ 2)ˆi+ (xsin θ 2 + ycos θ 2) ˆj+ zcos θ 2 ˆk ⎛ ⎝⎜ ⎞⎠⎟ = 0 + x(cos2θ 2 − ysin 2θ 2)− 2ycos θ 2sin θ 2 ⎛

⎝⎜ ⎞⎠⎟ˆi + 2xcosθ2sin

θ 2 + y(cos 2θ 2 − ysin 2θ 2) ⎛ ⎝⎜ ⎞⎠⎟ ˆj + z cos2θ2 + sin 2θ 2 ⎛ ⎝⎜ ⎞⎠⎟ ˆk = 0 + x cos( θ− ysinθ)ˆi + xsin( θ+ ycosθ)ˆj + zˆk

= 0, x cos( θ − ysinθ, x sinθ + ycosθ, z)

cosθ −sinθ 0 0 sinθ cosθ 0 0 0 0 1 0 0 0 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ x y z 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = x cosθ − ysinθ x sinθ + ycosθ 0 1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥

(23)

q2

q1pq1−1

q−12 = q

2q1

p q

1−1q2−1

= q

2q1

p q

2q1

### )

−1

The rotation using q1 and then using q2 = the rotation using q2q1

(24)

### (Spherical Linear Interpolation)

• A unit quaternion is a point on a 4D unit sphere.

Therefore, every point on a 4D unit sphere

represents a 3D rotation.

Interpolating orientations means moving on a 4D unit

(25)

### (Spherical Linear Interpolation)

SLERP(qa, qb, t) = sin ((1 − t)θ)

sinθ qa + sin (tθ)sinθ qb

cosθ = qa ⋅ qb

t ∈ [0,1] {qqab; , t = 0; , t = 1

LERP(qa, qb, t) = (1 − t)qa + tqb

θ = cos−1 (q

(26)

### (Spherical Linear Interpolation)

θ 1 − tθ a b q x y q = cos(tθ)x + sin(tθ)y

y = Normalize (b − (b ⋅ x)x) = Normalize (b − (b ⋅ a)a) = Normalize (b − cosθa) = b − cosθa

b − cosθa =

b − cosθa

(b − cosθa) ⋅ (b − cosθa)

= b − cosθa

b ⋅ b − 2(a ⋅ b)cosθ + (a ⋅ a)cos2θ

= b − cosθa

1 − 2cos2θ + cos2θ = b − cosθa1 − cos2θ = b − cosθasinθ

= cos(tθ)a + sin(tθ) b − cosθasinθ = (cos(tθ) − sin(tθ)cosθsinθ ) a + sin(tθ)sinθ b = sinθcos(tθ) − cosθsin(tθ)sinθ a + sin(tθ)sinθ b = sin(θ − tθ)sinθ a + sin(tθ)sinθ b

= sin ((1 − t)θ)

sinθ a + sin(tθ)sinθ b

∵ sin (α + β) = sinα cosβ + cosα sinβ

(27)

### (Spherical Linear Interpolation)

SLERP(qa, qb, t) = sin ((1 − t)θ)sinθ qa + sin (tθ)sinθ qb

= qa(qa−1qb)t = qb(qb−1qa)1−t = (qbqa−1)tqa = (qaqb−1)1−tqb

(28)

(29)

Updating...

관련 주제 :