Quaternion for Rotation Matrix
referenced video :
3D Rotations and Quaternion
referenced blog :
Quaternion
order of rotations 중요
한 축이 소실
되는 상황상속관계
여서Gimbal Lock
은 위의 그림과 같이상속관계에서의 2번째 축(빨강)이 -90도 혹은 90도 회전
했을 때상속관계에서의 1번째 축(초록)과 3번째 축(파랑)이 겹쳐서
같은 방향으로 회전하기 때문에 발생한다.특정 하나의 axis에 대한 회전(자유도=1)으로 제약 생겨버림
!Euler angles vs Quaternion :
Euler angles는 상속관계이므로 한 번에 계산이 불가능하여 순서대로 회전시켜야 하고, 짐벌락 현상이 발생할 수 있지만
Quaternion은 한 번에 계산 가능
하여 동시에 회전
시킬 수 있으며, 짐벌락 현상이 없다!
FOUR
coordinates!(one real, three imaginary)new property!
not commutative
: \(qp \neq pq\) for \(q, p \in H\)a pair of scalar and vector
quaternion product
: quaternion conjugate
:3D Rotation
: \(x\)를 \(u\)에 대해 \(\theta\)만큼 회전하고 싶다면Interpolating Rotation
:spherical linear interpolation (SLERP)
:Texture Maps
:angle-preserving(conformal)
maps에 쓰임!Beyond Quaternion … :
Lie algebras
and Lie Groups
으로도 3D rotations를 나타낼 수 있으며,
특히 statistics(averages) of rotations
를 구할 때 매우 유용!
exponential map
: axis/angle \(\rightarrow\) rotation matrix
logarithmic map
: rotation matrix \(\rightarrow\) axis/angle
4 \(\times\) 1 quaternion
\(q\) 으로 3 \(\times\) 3 rotation matrix
만드는 방법 : build_rotation(r)
def build_rotation(r):
norm = torch.sqrt(r[:,0]*r[:,0] + r[:,1]*r[:,1] + r[:,2]*r[:,2] + r[:,3]*r[:,3])
q = r / norm[:, None] # use normalized quaternion
R = torch.zeros((q.size(0), 3, 3), device='cuda')
r = q[:, 0]
x = q[:, 1]
y = q[:, 2]
z = q[:, 3]
R[:, 0, 0] = 1 - 2 * (y*y + z*z)
R[:, 0, 1] = 2 * (x*y - r*z)
R[:, 0, 2] = 2 * (x*z + r*y)
R[:, 1, 0] = 2 * (x*y + r*z)
R[:, 1, 1] = 1 - 2 * (x*x + z*z)
R[:, 1, 2] = 2 * (y*z - r*x)
R[:, 2, 0] = 2 * (x*z - r*y)
R[:, 2, 1] = 2 * (y*z + r*x)
R[:, 2, 2] = 1 - 2 * (x*x + y*y)
return R