동차 좌표계를 사용하는 가장 큰 장점 중 하나는 다양한 변환을 하나의 행렬로 통합할 수 있다는 점이다. 이를 통해 여러 변환을 연속해서 적용하는 과정을 단순화할 수 있다. 예를 들어, 2D 공간에서 객체를 회전시키고 평행 이동 시킨 후 다시 확대하고자 할 때, 각각의 변환을 개별적으로 적용하는 대신 하나의 복합 행렬을 이용하여 한 번에 계산할 수 있다.
동차 좌표계에서 2D 점 $(x, y)$는 3D 벡터 $(x, y, 1)$로 나타난다. 동차 좌표계의 이러한 확장은 다양한 기하학적 변환을 행렬 연산을 통해 쉽게 표현하고 계산할 수 있게 한다.
이동 변환 (Translation) 이동 변환은 점을 특정 벡터만큼 이동시키는 변환이다. 2D 평면에서 점 $(x, y)$를 $(t_x, t_y)$만큼 이동시키는 변환 행렬은 다음과 같다:
T = [ 1 0 t x 0 1 t y 0 0 1 ] \mathbf{T} =
\begin{bmatrix}
1 & 0 & t_x \\
0 & 1 & t_y \\
0 & 0 & 1
\end{bmatrix} T = 1 0 0 0 1 0 t x t y 1 이 변환 행렬을 통해 점 $(x, y, 1)$은 $(x + t_x, y + t_y, 1)$로 이동된다.
회전 변환 (Rotation) 회전 변환은 점을 원점 중심으로 $\theta$ 만큼 회전시키는 변환이다. 회전 변환 행렬은 다음과 같다:
R ( θ ) = [ cos θ − sin θ 0 sin θ cos θ 0 0 0 1 ] \mathbf{R}(\theta) =
\begin{bmatrix}
\cos\theta & -\sin\theta & 0 \\
\sin\theta & \cos\theta & 0 \\
0 & 0 & 1
\end{bmatrix} R ( θ ) = cos θ sin θ 0 − sin θ cos θ 0 0 0 1 이 변환 행렬을 통해 점 $(x, y, 1)$은 원점을 기준으로 $\theta$ 만큼 회전된 새로운 좌표로 변환된다.
확대 변환 (Scaling) 확대 변환은 점을 원점을 기준으로 일정 비율로 확대 또는 축소시키는 변환이다. 확대 변환 행렬은 다음과 같다:
S ( s x , s y ) = [ s x 0 0 0 s y 0 0 0 1 ] \mathbf{S}(s_x, s_y) =
\begin{bmatrix}
s_x & 0 & 0 \\
0 & s_y & 0 \\
0 & 0 & 1
\end{bmatrix} S ( s x , s y ) = s x 0 0 0 s y 0 0 0 1 여기서 $sx$와 $sy$는 각각 x축과 y축에 대한 확대 또는 축소 비율이다. 이 변환 행렬을 통해 점 $(x, y, 1)$은 $(sx \cdot x, sy \cdot y, 1)$로 변환된다.
여러 가지 변환을 연속적으로 수행하는 경우, 각 변환을 개별적으로 적용하는 대신 복합 행렬을 구하여 한 번에 변환할 수 있다. 복합 변환 행렬은 각 변환 행렬을 순서대로 곱하여 구할 수 있다.
예를 들어, 다음과 같은 변환을 수행한다고 가정하자:
이 변환들을 복합 변환 행렬로 나타내면:
T ⋅ R ( θ ) ⋅ S ( s x , s y ) = [ 1 0 t x 0 1 t y 0 0 1 ] ⋅ [ cos θ − sin θ 0 sin θ cos θ 0 0 0 1 ] ⋅ [ s x 0 0 0 s y 0 0 0 1 ] \mathbf{T} \cdot \mathbf{R}(\theta) \cdot \mathbf{S}(s_x, s_y) =
\begin{bmatrix}
1 & 0 & t_x \\
0 & 1 & t_y \\
0 & 0 & 1
\end{bmatrix}
\cdot
\begin{bmatrix}
\cos\theta & -\sin\theta & 0 \\
\sin\theta & \cos\theta & 0 \\
0 & 0 & 1
\end{bmatrix}
\cdot
\begin{bmatrix}
s_x & 0 & 0 \\
0 & s_y & 0 \\
0 & 0 & 1
\end{bmatrix} T ⋅ R ( θ ) ⋅ S ( s x , s y ) = 1 0 0 0 1 0 t x t y 1 ⋅ cos θ sin θ 0 − sin θ cos θ 0 0 0 1 ⋅ s x 0 0 0 s y 0 0 0 1 이 복합 변환 행렬을 통해 점 $(x, y, 1)$는 순서대로 이동, 회전 및 확대 변환을 적용받고 최종 새로운 좌표로 변환될 것이다.
단일 행렬로 복합 변환 적용
이제 위에서 언급한 각각의 변환 행렬을 실제로 곱해보자. 곱셈 과정은 각 행렬의 열과 행을 따라 요소를 곱하여 합산하는 방식이다.
먼저 확대 변환과 회전 변환 행렬을 곱한 결과는 다음과 같다:
R ( θ ) ⋅ S ( s x , s y ) = [ cos θ − sin θ 0 sin θ cos θ 0 0 0 1 ] ⋅ [ s x 0 0 0 s y 0 0 0 1 ] = [ s x cos θ − s y sin θ 0 s x sin θ s y cos θ 0 0 0 1 ] \mathbf{R}(\theta) \cdot \mathbf{S}(sx, sy) =
\begin{bmatrix}
\cos\theta & -\sin\theta & 0 \\
\sin\theta & \cos\theta & 0 \\
0 & 0 & 1
\end{bmatrix}
\cdot
\begin{bmatrix}
sx & 0 & 0 \\
0 & sy & 0 \\
0 & 0 & 1
\end{bmatrix}
=
\begin{bmatrix}
sx \cos\theta & -sy \sin\theta & 0 \\
sx \sin\theta & sy \cos\theta & 0 \\
0 & 0 & 1
\end{bmatrix} R ( θ ) ⋅ S ( s x , sy ) = cos θ sin θ 0 − sin θ cos θ 0 0 0 1 ⋅ s x 0 0 0 sy 0 0 0 1 = s x cos θ s x sin θ 0 − sy sin θ sy cos θ 0 0 0 1 이제 이동 변환 행렬을 곱하여 최종 복합 변환 행렬을 계산하자:
T ⋅ ( R ( θ ) ⋅ S ( s x , s y ) ) = [ 1 0 t x 0 1 t y 0 0 1 ] ⋅ [ s x cos θ − s y sin θ 0 s x sin θ s y cos θ 0 0 0 1 ] = [ s x cos θ − s y sin θ t x s x sin θ s y cos θ t y 0 0 1 ] \mathbf{T} \cdot (\mathbf{R}(\theta) \cdot \mathbf{S}(sx, sy)) =
\begin{bmatrix}
1 & 0 & tx \\
0 & 1 & ty \\
0 & 0 & 1
\end{bmatrix}
\cdot
\begin{bmatrix}
sx \cos\theta & -sy \sin\theta & 0 \\
sx \sin\theta & sy \cos\theta & 0 \\
0 & 0 & 1
\end{bmatrix}
=
\begin{bmatrix}
sx \cos\theta & -sy \sin\theta & tx \\
sx \sin\theta & sy \cos\theta & ty \\
0 & 0 & 1
\end{bmatrix} T ⋅ ( R ( θ ) ⋅ S ( s x , sy )) = 1 0 0 0 1 0 t x t y 1 ⋅ s x cos θ s x sin θ 0 − sy sin θ sy cos θ 0 0 0 1 = s x cos θ s x sin θ 0 − sy sin θ sy cos θ 0 t x t y 1 따라서, 복합 변환 행렬은:
T ⋅ R ( θ ) ⋅ S ( s x , s y ) = [ s x cos θ − s y sin θ t x s x sin θ s y cos θ t y 0 0 1 ] \mathbf{T} \cdot \mathbf{R}(\theta) \cdot \mathbf{S}(sx, sy) =
\begin{bmatrix}
sx \cos\theta & -sy \sin\theta & tx \\
sx \sin\theta & sy \cos\theta & ty \\
0 & 0 & 1
\end{bmatrix} T ⋅ R ( θ ) ⋅ S ( s x , sy ) = s x cos θ s x sin θ 0 − sy sin θ sy cos θ 0 t x t y 1 이제 이 복합 변환 행렬을 실제로 점에 적용해 보자. 예를 들어, 점 $(x,y)$가 $(2, 3)$이라 하고, 이동 벡터가 $(1,1)$, 회전 각도가 $45^\circ$ (즉, $\theta = \pi/4$), 그리고 확대 비율이 $sx = 2$, $sy = 3$ 라고 하자.
T ⋅ R ( θ ) ⋅ S ( s x , s y ) = [ 2 ⋅ cos π 4 − 3 ⋅ sin π 4 1 2 ⋅ sin π 4 3 ⋅ cos π 4 1 0 0 1 ] = [ 2 ⋅ 2 2 − 3 ⋅ 2 2 1 2 ⋅ 2 2 3 ⋅ 2 2 1 0 0 1 ] = [ 2 − 3 2 2 1 2 3 2 2 1 0 0 1 ] \mathbf{T} \cdot \mathbf{R}(\theta) \cdot \mathbf{S}(s_x, s_y) =
\begin{bmatrix}
2 \cdot \cos\frac{\pi}{4} & -3 \cdot \sin\frac{\pi}{4} & 1 \\
2 \cdot \sin\frac{\pi}{4} & 3 \cdot \cos\frac{\pi}{4} & 1 \\
0 & 0 & 1
\end{bmatrix}
=
\begin{bmatrix}
2 \cdot \frac{\sqrt{2}}{2} & -3 \cdot \frac{\sqrt{2}}{2} & 1 \\
2 \cdot \frac{\sqrt{2}}{2} & 3 \cdot \frac{\sqrt{2}}{2} & 1 \\
0 & 0 & 1
\end{bmatrix}
=
\begin{bmatrix}
\sqrt{2} & -\frac{3\sqrt{2}}{2} & 1 \\
\sqrt{2} & \frac{3\sqrt{2}}{2} & 1 \\
0 & 0 & 1
\end{bmatrix} T ⋅ R ( θ ) ⋅ S ( s x , s y ) = 2 ⋅ cos 4 π 2 ⋅ sin 4 π 0 − 3 ⋅ sin 4 π 3 ⋅ cos 4 π 0 1 1 1 = 2 ⋅ 2 2 2 ⋅ 2 2 0 − 3 ⋅ 2 2 3 ⋅ 2 2 0 1 1 1 = 2 2 0 − 2 3 2 2 3 2 0 1 1 1 이제 이 복합 변환 행렬을 점 $(2, 3, 1)$에 적용하면:
[ 2 − 3 2 2 1 2 3 2 2 1 0 0 1 ] ⋅ [ 2 3 1 ] = [ 2 ⋅ 2 + ( − 3 2 2 ) ⋅ 3 + 1 2 ⋅ 2 + 3 2 2 ⋅ 3 + 1 1 ] = [ 2 2 − 9 2 2 + 1 2 2 + 9 2 2 + 1 1 ] = [ − 5 2 2 + 1 13 2 2 + 1 1 ] \begin{bmatrix}
\sqrt{2} & -\frac{3\sqrt{2}}{2} & 1 \\
\sqrt{2} & \frac{3\sqrt{2}}{2} & 1 \\
0 & 0 & 1
\end{bmatrix}
\cdot
\begin{bmatrix}
2 \\
3 \\
1
\end{bmatrix}
=
\begin{bmatrix}
\sqrt{2} \cdot 2 + \left(-\frac{3\sqrt{2}}{2}\right) \cdot 3 + 1 \\
\sqrt{2} \cdot 2 + \frac{3\sqrt{2}}{2} \cdot 3 + 1 \\
1
\end{bmatrix}
=
\begin{bmatrix}
2\sqrt{2} - \frac{9\sqrt{2}}{2} + 1 \\
2\sqrt{2} + \frac{9\sqrt{2}}{2} + 1 \\
1
\end{bmatrix}
=
\begin{bmatrix}
-\frac{5\sqrt{2}}{2} + 1 \\
\frac{13\sqrt{2}}{2} + 1 \\
1
\end{bmatrix} 2 2 0 − 2 3 2 2 3 2 0 1 1 1 ⋅ 2 3 1 = 2 ⋅ 2 + ( − 2 3 2 ) ⋅ 3 + 1 2 ⋅ 2 + 2 3 2 ⋅ 3 + 1 1 = 2 2 − 2 9 2 + 1 2 2 + 2 9 2 + 1 1 = − 2 5 2 + 1 2 13 2 + 1 1 따라서 최종 변환된 좌표는:
( − 5 2 2 + 1 , 13 2 2 + 1 ) \left(-\frac{5\sqrt{2}}{2} + 1, \frac{13\sqrt{2}}{2} + 1\right) ( − 2 5 2 + 1 , 2 13 2 + 1 ) 이로써 동차 좌표를 사용한 복합 변환의 효율성을 확인할 수 있다. 변환을 개별적으로 적용하는 대신, 복합 행렬을 사용함으로써 보다 단순하고 간결하게 변환을 수행할 수 있다.