[그래픽스] 변환(Transformation)

YEOM JINSEOP·2023년 11월 19일
0

Computer Graphics

목록 보기
3/14

변환(Transform)

  • Scaling과 Rotation은 선형변환(Linear Transform) 범주에 속한다.
  • 이외의 변환으로 이동(Translation)이 존재한다.

1. 축소,확대 (Scaling )

2D Scaling

  • 2차원 축소확대는 다음과 같은 2 ×\times 2 행렬로 표현된다. (sx,sys_x, s_y는 scaling factor)
    \\
    S=(sx00sy)S = \begin{pmatrix} s_x & 0 \\ 0 & s_y \end{pmatrix}

  • 2차원 벡터 (x,y)(x, y)는 행렬-벡터 곱셈을 통해 scaling 된다.
    \\
    S=(sx00sy)(xy)=(sxxsyy)S = \begin{pmatrix} s_x & 0 \\ 0 & s_y \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} s_xx \\ s_yy \end{pmatrix}

  • 동차 좌표(homogeneous coordinate)를 다루기 위해서는 2 ×\times 2 행렬 형태를 3 ×\times 3 행렬 형태로 변경한다.
    \\
    S=(sx000sy0001)S = \begin{pmatrix} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & 1 \end{pmatrix}

3D Scaling

  • 3차원 축소확대는 다음과 같은 3 ×\times 3 행렬로 표현된다. (sx,sy,szs_x, s_y, s_z는 scaling factor)
    \\
    S=(sx000sy000sz)S = \begin{pmatrix} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & s_z \\ \end{pmatrix}

  • 3차원 벡터 (x,y)(x, y)는 행렬-벡터 곱셈을 통해 scaling 된다.
    \\
    S=(sx000sy000sz)(xyz)=(sxxsyyszz)S = \begin{pmatrix} s_x & 0 & 0\\ 0 & s_y & 0\\ 0 & 0 & s_z \end{pmatrix} \begin{pmatrix} x \\ y \\ z \end{pmatrix} = \begin{pmatrix} s_xx \\ s_yy \\ s_zz \end{pmatrix}

  • 동차 좌표(homogeneous coordinate)를 다루기 위해서는 3 ×\times 3 행렬 형태를 4 ×\times 4 행렬 형태로 변경한다.
    \\
    S=(sx0000sy0000sz00001)S = \begin{pmatrix} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ 0 & 0 & s_z & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}

2. 회전(rotation)

2D rotation

  • (xy)=(cosθsinθsinθcosθ)(xy)\begin{pmatrix} x' \\ y' \end{pmatrix} = \begin{pmatrix} cos\theta & -sin\theta \\ sin\theta & cos\theta \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix}

  • 2D rotation R(θ)R(\theta)의 유도 과정은 아래와 같다.

  • 동차 좌표(homogeneous coordinate)를 다루기 위해서는 2 ×\times 2 행렬 형태를 3 ×\times 3 행렬 형태로 변경한다.
    \\
    S=(cosθsinθ0sinθcosθ0001)S = \begin{pmatrix} cos\theta & -sin\theta & 0 \\ sin\theta & cos\theta & 0 \\ 0 & 0 & 1 \end{pmatrix}

3D rotation

  • 2D rotation에서는 회전 중심(center of rotation)을 필요로 하는데 반해,
    3D rotation은 회전축(axis of rotation)을 필요로 한다.

  • Rz(θ):R_z(\theta): zz 축을 중심으로 θ\theta 만큼 회전 ➡️ x,yx, y 좌표가 바뀜.
    \\
    (xyz)=(cosθsinθ0sinθcosθ0001)(xyz)\begin{pmatrix} x' \\ y' \\ z' \end{pmatrix} = \begin{pmatrix} cos\theta & -sin\theta & 0 \\ sin\theta & cos\theta & 0 \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x \\ y \\ z \end{pmatrix}

  • Rx(θ):R_x(\theta): xx 축을 중심으로 θ\theta 만큼 회전 ➡️ y,zy, z 좌표가 바뀜.
    \\
    (xyz)=(1000cosθsinθ0sinθcosθ)(xyz)\begin{pmatrix} x' \\ y' \\ z' \end{pmatrix} = \begin{pmatrix} 1 & 0 & 0 \\ 0 & cos\theta & -sin\theta \\ 0 & sin\theta & cos\theta \end{pmatrix} \begin{pmatrix} x \\ y \\ z \end{pmatrix}

  • Ry(θ):R_y(\theta): yy 축을 중심으로 θ\theta 만큼 회전 ➡️ x,zx, z 좌표가 바뀜.\\
    (xyz)=(cosθ0sinθ010sinθ0cosθ)(xyz)\begin{pmatrix} x' \\ y' \\ z' \end{pmatrix} = \begin{pmatrix} cos\theta & 0 & sin\theta \\ 0 & 1 & 0 \\ -sin\theta & 0 & cos\theta \end{pmatrix} \begin{pmatrix} x \\ y \\ z \end{pmatrix}

  • 동차 좌표(homogeneous coordinate)를 다루기 위해서는 3 ×\times 3 행렬 형태를 4 ×\times 4 행렬 형태로 변경한다.
    \\
    Rz(θ)=(xyz1)=(cosθsinθ00sinθcosθ0000100001)(xyz1)R_z(\theta) = \begin{pmatrix} x' \\ y' \\ z' \\ 1 \end{pmatrix} = \begin{pmatrix} cos\theta & -sin\theta & 0 & 0 \\ sin\theta & cos\theta & 0 & 0\\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x \\ y \\ z \\ 1 \end{pmatrix}
    \\
    Rx(θ)=(xyz1)=(10000cosθsinθ00sinθcosθ00001)(xyz1)R_x(\theta)= \begin{pmatrix} x' \\ y' \\ z' \\ 1 \end{pmatrix} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & cos\theta & -sin\theta & 0 \\ 0 & sin\theta & cos\theta & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x \\ y \\ z \\ 1 \end{pmatrix}
    \\
    Ry(θ)=(xyz1)=(cosθ0sinθ00100sinθ0cosθ00001)(xyz1)R_y(\theta)=\begin{pmatrix} x' \\ y' \\ z \\ 1 \end{pmatrix} = \begin{pmatrix} cos\theta & 0 & sin\theta & 0\\ 0 & 1 & 0 & 0\\ -sin\theta & 0 & cos\theta & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x \\ y \\ z \\ 1 \end{pmatrix}


3. 이동 (Translation)

2D Translation

  • 이동은 선형 변환(linear transform)의 범주에 속하지 않으며, 다음처럼 벡터 덧셈으로 구현된다.
    행렬 곱셈으로 구현되는 sacling과 translation과는 다르다.
    \\
    (xy)+(dxdy)=(x+dxy+dy)\begin{pmatrix} x \\ y \end{pmatrix}+ \begin{pmatrix} d_x \\ d_y \end{pmatrix} = \begin{pmatrix} x + d_x \\ y + d_y \end{pmatrix}

  • 하지만, 동차 좌표(homogeneous coordinates)를 사용하면, translation 역시 행렬 곱셈으로 구현될 수 있다.
    한 점의 2차원 카테시안 좌표 (x,y)(x, y)가 주어질 때 이에 대한 동차 좌표는 간단히 (x,y,1)(x, y, 1)로 표현될 수 있다.
    이때 이동 행렬은 다음과 같다.
    \\
    (10dx01dy001)(xy1)=(x+dxy+dy1)\begin{pmatrix} 1 & 0 & d_x \\ 0 & 1 & d_y \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x \\ y \\ 1 \end{pmatrix}= \begin{pmatrix} x + d_x \\ y + d_y \\ 1 \end{pmatrix}

3D Translation

  • 동차 좌표(homogeneous coordinates)를 이용한 3차원 이동
    \\
    (100dx010dy001dz0001)(xyz1)=(x+dxy+dyz+dz1)\begin{pmatrix} 1 & 0 & 0 & d_x \\ 0 & 1 & 0 & d_y \\ 0 & 0 & 1 & d_z \\ 0 & 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x \\ y \\ z \\ 1 \end{pmatrix}= \begin{pmatrix} x+d_x\\y+d_y\\z+d_z\\1 \end{pmatrix}

4. 변환의 결합

  • 행렬 곱셈서는 교환 법칙이 성립하지 않는다. 따라서 변환을 적용하는 순서에 따라 결과가 달라진다.
  • 먼저 실행되는 변환이 오른쪽에 위치한다.

5. 역변환

  • TT의 역변환을 T1T^{-1} 이라고 표기하고, 실제로 TT의 역행렬이다.

  • 이동(Translation)의 역변환
    \\
    T=(100dx010dy001dz0001), T1=(100dx010dy001dz0001)T = \begin{pmatrix} 1 & 0 & 0 & d_x \\ 0 & 1 & 0 & d_y \\ 0 & 0 & 1 & d_z \\ 0 & 0 & 0 & 1 \end{pmatrix}, \ T^{-1}= \begin{pmatrix} 1 & 0 & 0 & -d_x \\ 0 & 1 & 0 & -d_y \\ 0 & 0 & 1 & -d_z \\ 0 & 0 & 0 & 1 \end{pmatrix}

  • Scaling의 역변환
    \\
    S=(sx0000sy0000sz00001),S1=(1/sx00001/sy00001/sz00001)S = \begin{pmatrix} s_x & 0 & 0 & 0\\ 0 & s_y & 0 & 0\\ 0 & 0 & s_z & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}, S^{-1}= \begin{pmatrix} 1/s_x & 0 & 0 & 0\\ 0 & 1/s_y & 0 & 0\\ 0 & 0 & 1/s_z & 0\\ 0 & 0 & 0 & 1 \end{pmatrix}

  • Rotation의 역변환
    \\
    R=(uxvxnxuyvynyuzvznz),RT=(uxuyuzvxvyvznxnynz)R = \begin{pmatrix} u_x & v_x & n_x \\ u_y & v_y & n_y \\ u_z & v_z & n_z \end{pmatrix} ,R^T= \begin{pmatrix} u_x & u_y & u_z \\ v_x & v_y & v_z \\ n_x & n_y & n_z \end{pmatrix}
    \\
    [식 유도하기 ]
    object space의 기저 {u,v,n}\{u, v, n\}이 직교 적교 성질을 가지므로,
    하나의 기저 벡터가 자신과 내적되었을 때 그 결과는 1이다. ➡️ uu=vv=nn=1u \cdot u =v \cdot v=n \cdot n=1
    반면, 서로 다른 기저 벡터간 내적은 0이다. ➡️ uv=vn=nu=0u \cdot v =v \cdot n=n \cdot u=0
    이를 이용해서, rotation 행렬 RR과 그 전치행렬 RTR^{T}의 곱을 정리하면 다음과 같다.
    \\
    RTR=(uxuyuzvxvyvznxnynz)(uxvxnxuyvynyuzvznz)R^TR = \begin{pmatrix} u_x & u_y & u_z \\ v_x & v_y & v_z \\ n_x & n_y & n_z \end{pmatrix} \begin{pmatrix} u_x & v_x & n_x \\ u_y & v_y & n_y \\ u_z & v_z & n_z \end{pmatrix}

0개의 댓글

관련 채용 정보