아롱이 탐험대

2D Transformation and Viewing 본문

CS/Computer graphics

2D Transformation and Viewing

ys_cs17 2022. 4. 7. 23:06
반응형

Redering이란 object를 스크린에 투영하는 과정에서 필요한 도구들이다.

이전 시간에 살펴본 Redering pipline에서 2D를 담당하는 부분은 크게 3가지가 있었다.

(1) Clipping: window 밖에 있는 기하학적 요소의 clip 부분을 clipping 한다. 필요없는 요소들을 자른다는 말이다.

(2) Viewport transformation: 스크린으로부터 clip된 요소들을 이미지 좌표계로 변환한다.

(3) Scan conversion: 스크린 좌표에 있는 대표적인 요소의 픽셀을 채운다.

위 3가지 process를 통해 2D primitive를 최종적인 image로 변환한다.

 

2D object의 표현에 대해 알아보자.

Graphical object에서 기하학적 요소는 점, 선, 다각형, 커브이고, 구성 요소는 다이어그램과 비디오 신호이다.

수학적 표현은 점과 선으로 구성된다.

 

Homogeneous Coordinates

Homogeneous 좌표계는 single matrix 형식에서 우리에게 scaling, roation, translation을 할 수 있게 해준다.

3차원 동차 좌표인 $(x, y, z)$를 2차원으로 변환하기 위해 w로 나누어 줌으로써 $(\frac{x}{w},\frac{y}{w})$로 표현하게 한다. 여기서 w 값은 카메라로부터의 거리에 따라 달라진다.

마찬가지로 4차원 좌표도 3차원으로 변환할 수 있다.

$(3, 3)$이라는 점은 실제로는 $(3, 3, 1), (6, 6, 2), \cdots$ 이다. $h = 1$인 평면을 2차원으로 본다. 왜 이렇게 변환할까?

 

Basic Transformation

기존 $P(x, y)$ 를 $P'(x^{*}, y^{*})$ 로 transformation하는 방법은 translation 행렬 $M$을 통해 진행할 수 있다.

 

Translation matrix

$$\begin{pmatrix}
1 \ 0 \ t_{x} \\
0 \ 1 \ t_{y} \\
0 \ 0 \ 1
\end{pmatrix}$$

 

Scaling matrix

$$\begin{pmatrix}
S_{x} \ 0 \ 0 \\
0 \ S_{y} \ 0 \\
0 \ 0 \ 1
\end{pmatrix}$$

 

Rotation matrix

$$\begin{pmatrix}
\cos{\theta} \ -\sin{\theta} \ 0 \\
\sin{\theta} \ \cos{\theta} \ 0 \\
0 \ \ \ \ \ \ \ 0 \ \ \ \ \ 1
\end{pmatrix}$$

 

Translation example

 

$$\begin{pmatrix}
1 \ 0 \ t_{x} \\
0 \ 1 \ t_{y} \\
0 \ 0 \ 1
\end{pmatrix}

\begin{pmatrix}
x \\
y\\
1
\end{pmatrix} =

\begin{pmatrix}
x^{*} \\
y^{*}\\
1
\end{pmatrix}$$

 

Shearing

x 축 방향

$$x{*} = x  + ay, \ \ \ y^{*}=y$$$$\text{SHx} =

\begin{pmatrix}
1 \ a \ 0 \\
0 \ 1 \ 0 \\
0 \ 0 \ 1
\end{pmatrix}$$

y축 방향

$$x{*} = x , \ \ \ y^{*}=y + bx$$

 

$$\text{SHy} =

\begin{pmatrix}
1 \ 0 \ 0 \\
b \ 1 \ 0 \\
0 \ 0 \ 1
\end{pmatrix}$$

 

Composite Transformation

각 transformation metrics를 product dot 연산을 해줌으로써 복합적인 변환을 할 수 있다. (transformation+rotation이면 product dot 연산을 통해 한번에 진행할 수 있음)

 

Transformations

$$M = T(tx_{2}, ty_{2}) \cdot T(tx_{1}, ty_{1}) = T(tx_{1}+tx_{2}, ty_{1}+ty_{2)}$$

$$M = \begin{pmatrix}
1 \ 0 \ tx_{1} \\
0 \ 1 \ ty_{1} \\
0 \ 0 \ 1
\end{pmatrix}
\begin{pmatrix}
1 \ 0 \ tx_{2} \\
0 \ 1 \ ty_{2} \\
0 \ 0 \ 1
\end{pmatrix}
= \begin{pmatrix}
1 \ 0 \ tx_{1}+tx_{2} \\
0 \ 1 \ ty_{1}+ty_{2} \\
0 \ 0 \ \  \ \ \ 1
\end{pmatrix}$$

 

Scalings

$$M = S(Sx_{2}, Sy_{2}) \cdot S(Sx_{1}, Sy_{1}) = S(Sx_{1}Sx_{2}, Sy_{1}Sy_{2)}$$

$$M = \begin{pmatrix}
Sx_{2} \ 0 \ 0 \\
0 \ Sy_{2} \ 0 \\
0 \ 0 \ 1
\end{pmatrix}
\begin{pmatrix}
Sx_{1} \ 0 \ 0 \\
0 \ Sy_{1} \ 0 \\
0 \ 0 \ 1
\end{pmatrix}
=
\begin{pmatrix}
Sx_{1}Sx_{2} \ 0 \ 0 \\
0 \ Sy_{1}Sy_{2} \ 0 \\
0 \ \ \  \ 0 \ \ \ \  1
\end{pmatrix}$$

 

Rotations

$$M = R(\theta_{2}) \cdot R(\theta_{1}) = R(\theta_{1}+\theta_{2})$$

$$M = \begin{pmatrix}
\cos{\theta_{2}} \ -\sin{\theta_{2}} \ 0 \\
\sin{\theta_{2}} \ \cos{\theta_{2}} \ 0 \\
0 \ \ \ \ \ \ \ \ \  0 \  \ \ \ \ 1
\end{pmatrix}
\begin{pmatrix}
\cos{\theta_{1}} \ -\sin{\theta_{1}} \ 0 \\
\sin{\theta_{1}} \ \cos{\theta_{1}} \ 0 \\
0 \ \ \ \ \ \ \ \ \  0 \  \ \ \ \ 1
\end{pmatrix}
=
\begin{pmatrix}
\cos{(\theta_{1}+\theta_{2})} \ -\sin{(\theta_{1}+\theta_{2})} \ 0 \\
\sin{(\theta_{1}+\theta_{2})} \ \cos{(\theta_{1}+\theta_{2})} \ 0 \\
0 \ \ \  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 0 \ \ \ \ \ \ 1
\end{pmatrix}$$

 

Scaling relative to a fixed point

임의의 점에서 scaling을 진행해보자. 일반적인 scaling과는 다르게 임의의 점에서 scaling은 원점에서 scaling을 진행하고 다시 임의의 점으로 돌아간다. 그냥 scaling을 하면 원 위치를 잃을 수 있다. 따라서 수식은 다음과 같다.

$$M = T(tx, ty) \cdot S(Sx, Sy) \cdot T(-tx, -ty)$$

수식을 보면 첫 번째 transformation을 통해 원점으로 이동한 후 scaling을 진행하고, 다시 원래 좌표로 돌아간다.

$$M =\begin{pmatrix}
1 \ 0 \ tx \\
0 \ 1 \ ty \\
0 \ 0 \ 1
\end{pmatrix}
\begin{pmatrix}
Sx \ 0 \ 0 \\
0 \ Sy \ 0 \\
0 \ 0 \ 1
\end{pmatrix}
\begin{pmatrix}
1 \ 0 \ -tx \\
0 \ 1 \ -ty \\
0 \ \ \ 0 \ \ \ 1
\end{pmatrix}
= \begin{pmatrix}
Sx \ 0 \ (1-Sx)tx \\
0 \ Sy \ (1-Sy)ty \\
0 \ \ 0 \ \ \ \ 1
\end{pmatrix}$$

 

Rotation about a pivot point

행렬의 중심인 pivot point를 기준으로 회전하는 방법이다. 위 scaling과 방법이 유사하다.

원점으로 이동 후 회전 뒤 다시 해당 점으로 이동한다.

$$M = T(tx, ty) \cdot R(\theta) \cdot T(-tx, -ty)$$

$$M = \begin{pmatrix}
\cos{\theta} \ \ -\sin{\theta} \ \ \ tx(1-\cos{\theta})+ty\sin{\theta} \\
\sin{\theta}\ \ \cos{\theta} \ \ \ ty(1-\cos{\theta}) -tx \sin{\theta} \\
0 \ \ \ \ \ \ \ \ \  \ \  \ \ \ \  \ \ \ \ 0 \ \ \ \ \ \ \  \ \ \ \ \  \ \ \ \ 1
\end{pmatrix}$$

 

 

모든 변환은 결합 법칙교환 법칙이 성립된다.

 

Tranformation 종류

(1) Rigid Body Transformation (강체 변환)

: 물체 자체의 모습은 변화하지 않는다. 이동 변환, 회전 변환 등이 포함된다.

 

(2) Simiarity Transformation (유사 변환)

: 물체면 사이의 각이 유지되고, 내부 정점간의 거리가 일정한 비율로 유지된다. 강체 변환과 균등 크기 조절 변환, 반사 변환이 포함된다.

 

(3) Affine Transformation (어파인 변환)

: 직선은 직선으로, 다각형은 다각형으로 물체의 타입이 유지되고 평행선도 보존된다. 변환 행렬의 마지막 행이 항상 (0, 0, 1)로 끝난다. 유사 변환, 차등 크기 조절 변환, 전단 변환이 포함된다.

 

(4) Perspective Transoformation (원근 변환)

: 평행선이 만나고, 직선이 직선으로 유지 된다. 마지막 행이 (0, 0, 1)이 아니다.

 

(5) Linear Transformation (선형 변환)

: 어파인 변환 + 원근 변환이다. 선형 조합으로 표시되는 변환이다.

 

 

반응형

'CS > Computer graphics' 카테고리의 다른 글

Overview of computer graphics  (0) 2022.04.06
Comments