3차원 동차좌표계에서는 좌표 $\mathbf{p} = (x, y, z)$ 를 동차 좌표 $\mathbf{P}_h = (x, y, z, w)$ 로 표현한다. 동차좌표계의 가장 큰 장점은 기하학적 변환(회전, 이동, 스케일링 등)을 행렬 연산으로 통일되게 다룰 수 있다는 점이다.
3차원 공간에서의 점 $\mathbf{p}$ 를 동차 좌표계로 표현하면 다음과 같이 나타낼 수 있다:
P h = [ x y z w ] \mathbf{P}_h = \begin{bmatrix} x \\ y \\ z \\ w \end{bmatrix} P h = x y z w 여기서 $w$ 는 동차 좌표(w-좌표)로, 일반적으로 $w = 1$ 로 설정된다. 따라서, 원래의 좌표 $\mathbf{p}$ 는 $\mathbf{P}_h$ 에서 $w$ 를 나누어 얻는다:
p = [ x ′ y ′ z ′ ] = [ x w y w z w ] \mathbf{p} = \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix} = \begin{bmatrix} \frac{x}{w} \\ \frac{y}{w} \\ \frac{z}{w} \end{bmatrix} p = x ′ y ′ z ′ = w x w y w z 3차원 공간에서의 변환을 동차좌표계로 표현하기 위해서는 4x4 변환행렬을 사용한다. 변환행렬은 다음과 같은 형태를 갖는다:
T = [ a 11 a 12 a 13 a 14 a 21 a 22 a 23 a 24 a 31 a 32 a 33 a 34 a 41 a 42 a 43 a 44 ] \mathbf{T} = \begin{bmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{43} & a_{44} \end{bmatrix} T = a 11 a 21 a 31 a 41 a 12 a 22 a 32 a 42 a 13 a 23 a 33 a 43 a 14 a 24 a 34 a 44 변환된 동차 좌표 $\mathbf{P}'_h$ 는 다음과 같이 계산된다:
P h ′ = T P h \mathbf{P}'_h = \mathbf{T} \mathbf{P}_h P h ′ = T P h 이동 변환은 공간의 점을 일정한 벡터 $\mathbf{d} = (d_x, d_y, d_z)$ 만큼 이동시키는 변환이다. 이를 동차 좌표계로 표현하면 다음과 같다:
T translation = [ 1 0 0 d x 0 1 0 d y 0 0 1 d z 0 0 0 1 ] \mathbf{T}_\text{translation} = \begin{bmatrix} 1 & 0 & 0 & d_x \\ 0 & 1 & 0 & d_y \\ 0 & 0 & 1 & d_z \\ 0 & 0 & 0 & 1 \end{bmatrix} T translation = 1 0 0 0 0 1 0 0 0 0 1 0 d x d y d z 1 회전 변환은 3차원 공간의 점을 주어진 축을 중심으로 회전시키는 변환이다. 각 축에 대한 회전행렬은 아래와 같다:
X축 회전
T rotation, X ( θ ) = [ 1 0 0 0 0 cos θ − sin θ 0 0 sin θ cos θ 0 0 0 0 1 ] \mathbf{T}_\text{rotation, X}(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos\theta & -\sin\theta & 0 \\ 0 & \sin\theta & \cos\theta & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} T rotation, X ( θ ) = 1 0 0 0 0 cos θ sin θ 0 0 − sin θ cos θ 0 0 0 0 1 Y축 회전
T rotation, Y ( θ ) = [ cos θ 0 sin θ 0 0 1 0 0 − sin θ 0 cos θ 0 0 0 0 1 ] \mathbf{T}_\text{rotation, Y}(\theta) = \begin{bmatrix} \cos\theta & 0 & \sin\theta & 0 \\ 0 & 1 & 0 & 0 \\ -\sin\theta & 0 & \cos\theta & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} T rotation, Y ( θ ) = cos θ 0 − sin θ 0 0 1 0 0 sin θ 0 cos θ 0 0 0 0 1 Z축 회전
T rotation, Z ( θ ) = [ cos θ − cos θ 0 0 sin θ cos θ 0 0 0 0 1 0 0 0 0 1 ] \mathbf{T}_\text{rotation, Z}(\theta) = \begin{bmatrix} \cos\theta & -\cos\theta & 0 & 0 \\ \sin\theta & \cos\theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} T rotation, Z ( θ ) = cos θ sin θ 0 0 − cos θ cos θ 0 0 0 0 1 0 0 0 0 1 스케일링 변환은 점을 원점에 대한 일정 비율로 확대하거나 축소시키는 변환이다. 스케일링 행렬은 다음과 같다:
T scaling = [ s x 0 0 0 0 s y 0 0 0 0 s z 0 0 0 0 1 ] \mathbf{T}_\text{scaling} = \begin{bmatrix} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ 0 & 0 & s_z & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} T scaling = s x 0 0 0 0 s y 0 0 0 0 s z 0 0 0 0 1 여기서 $s_x$, $s_y$, $s_z$ 는 각각 x, y, z축 방향의 스케일링 비율이다.
여러 변환을 연속적으로 적용하려면 각 변환 행렬을 곱셈하여 하나의 변환 행렬로 결합할 수 있다. 예를 들어, 먼저 이동하고 회전한 다음 스케일링을 적용하려면 다음과 같이 행렬들을 곱셈한다:
T combined = T scaling ⋅ T rotation ⋅ T translation \mathbf{T}_\text{combined} = \mathbf{T}_\text{scaling} \cdot \mathbf{T}_\text{rotation} \cdot \mathbf{T}_\text{translation} T combined = T scaling ⋅ T rotation ⋅ T translation 이렇게 변환 행렬을 결합하면 단 한 번의 행렬 곱셈으로 일련의 변환을 적용할 수 있다.
하나의 예제로 x축 방향으로 2 단위 이동, z축 회전 90도 ( $\theta = \frac{\pi}{2}$ ), 그리고 모든 축에 대해 0.5 비율로 스케일링 하는 복합 변환을 보겠다.
T translation = [ 1 0 0 2 0 1 0 0 0 0 1 0 0 0 0 1 ] \mathbf{T}_\text{translation} = \begin{bmatrix} 1 & 0 & 0 & 2 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} T translation = 1 0 0 0 0 1 0 0 0 0 1 0 2 0 0 1 T rotation, Z ( π 2 ) = [ cos ( π 2 ) − sin ( π 2 ) 0 0 sin ( π 2 ) cos ( π 2 ) 0 0 0 0 1 0 0 0 0 1 ] = [ 0 − 1 0 0 1 0 0 0 0 0 1 0 0 0 0 1 ] \mathbf{T}_\text{rotation, Z}\left( \frac{\pi}{2} \right) = \begin{bmatrix} \cos\left(\frac{\pi}{2}\right) & -\sin\left(\frac{\pi}{2}\right) & 0 & 0 \\ \sin\left(\frac{\pi}{2}\right) & \cos\left(\frac{\pi}{2}\right) & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} = \begin{bmatrix} 0 & -1 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} T rotation, Z ( 2 π ) = cos ( 2 π ) sin ( 2 π ) 0 0 − sin ( 2 π ) cos ( 2 π ) 0 0 0 0 1 0 0 0 0 1 = 0 1 0 0 − 1 0 0 0 0 0 1 0 0 0 0 1 T scaling = [ 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 1 ] \mathbf{T}_\text{scaling} = \begin{bmatrix} 0.5 & 0 & 0 & 0 \\ 0 & 0.5 & 0 & 0 \\ 0 & 0 & 0.5 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} T scaling = 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 1 T combined = T scaling ⋅ T rotation, Z ( π 2 ) ⋅ T translation \mathbf{T}_\text{combined} = \mathbf{T}_\text{scaling} \cdot \mathbf{T}_\text{rotation, Z}\left( \frac{\pi}{2} \right) \cdot \mathbf{T}_\text{translation} T combined = T scaling ⋅ T rotation, Z ( 2 π ) ⋅ T translation T combined = [ 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 1 ] ⋅ [ 0 − 1 0 0 1 0 0 0 0 0 1 0 0 0 0 1 ] ⋅ [ 1 0 0 2 0 1 0 0 0 0 1 0 0 0 0 1 ] \mathbf{T}_\text{combined} = \begin{bmatrix} 0.5 & 0 & 0 & 0 \\ 0 & 0.5 & 0 & 0 \\ 0 & 0 & 0.5 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} 0 & -1 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} 1 & 0 & 0 & 2 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} T combined = 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 1 ⋅ 0 1 0 0 − 1 0 0 0 0 0 1 0 0 0 0 1 ⋅ 1 0 0 0 0 1 0 0 0 0 1 0 2 0 0 1 T combined = [ 0 − 0.5 0 0 0.5 0 0 1 0 0 0.5 0 0 0 0 1 ] \mathbf{T}_\text{combined} = \begin{bmatrix} 0 & -0.5 & 0 & 0 \\ 0.5 & 0 & 0 & 1 \\ 0 & 0 & 0.5 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} T combined = 0 0.5 0 0 − 0.5 0 0 0 0 0 0.5 0 0 1 0 1 이 변환 행렬을 사용하여 동차 좌표 $\mathbf{P}_{h}$에 적용하면, 해당 점에 대해 일련의 변환이 적용된다.