AEiE0805 Two-dimensional transformation¶
2D coordinate and matrix fundamentals¶
- Homogeneous coordinates let translation be expressed as matrix multiplication.
- A 2D point \((x,y)\) is written as column vector \([x\ y\ 1]^T\).
- Composite transforms are formed by multiplying matrices in sequence.
- Order matters: matrix multiplication is not commutative.
Translation by \((t_x,t_y)\):
\[
T=\begin{bmatrix}
1 & 0 & t_x \\
0 & 1 & t_y \\
0 & 0 & 1
\end{bmatrix}
\]
Scaling by \((s_x,s_y)\):
\[
S=\begin{bmatrix}
s_x & 0 & 0 \\
0 & s_y & 0 \\
0 & 0 & 1
\end{bmatrix}
\]
Rotation by angle \(\theta\) about the origin:
\[
R=\begin{bmatrix}
\cos\theta & -\sin\theta & 0 \\
\sin\theta & \cos\theta & 0 \\
0 & 0 & 1
\end{bmatrix}
\]
Reflection about x-axis:
\[
\begin{bmatrix}
1 & 0 & 0 \\
0 & -1 & 0 \\
0 & 0 & 1
\end{bmatrix}
\]
Shear in x-direction with factor \(sh_x\):
\[
\begin{bmatrix}
1 & sh_x & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{bmatrix}
\]
2D composite transformation and viewing¶
- To rotate about an arbitrary point \((x_r,y_r)\), translate that point to the origin, rotate, then translate back.
- Symbolically: \(T(x_r,y_r)RT(-x_r,-y_r)\).
- With column vectors, the rightmost matrix acts first.
Typical viewing order:
- Model objects in world coordinates.
- Select window in world coordinates.
- Clip primitives to the window.
- Map window to viewport.
- Convert to device or screen coordinates.
Window-to-viewport mapping:
\[
x_v = x_{vmin} + (x_w-x_{wmin})\frac{x_{vmax}-x_{vmin}}{x_{wmax}-x_{wmin}}
\]
\[
y_v = y_{vmin} + (y_w-y_{wmin})\frac{y_{vmax}-y_{vmin}}{y_{wmax}-y_{wmin}}
\]
2D clipping distinctions¶
| Algorithm | Main idea | Fast cue |
|---|---|---|
| Cohen-Sutherland | Region codes and repeated endpoint updates | Bit-code logic |
| Liang-Barsky | Parametric line clipping using inequalities | Fewer computations for many cases |
- Cohen-Sutherland divides the plane into 9 regions around the window.
- If bitwise OR of outcodes is zero, the line is trivially accepted.
- If bitwise AND is nonzero, the line is trivially rejected.
- Liang-Barsky uses \(P(t)=P_1+t(P_2-P_1)\) with \(0 \le t \le 1\).
- Liang-Barsky computes entering and leaving parameter limits directly.
Recognition cues for 2D transformation¶
- "Bitwise test" indicates Cohen-Sutherland.
- "Parametric clipping" indicates Liang-Barsky.
- "Translation cannot be represented by 2x2 matrix alone" motivates homogeneous coordinates.
- "Transform about arbitrary point" means translate, transform, translate back.
Common traps in 2D transformation¶
- Rotation matrix sign errors are common: counterclockwise uses \(-\sin\theta\) in the top-right position.
- Reflection about x-axis changes the sign of \(y\), not \(x\).
- Composite-transform order is easy to reverse; follow the intended physical steps.
- Clipping is a viewing-stage operation, not a replacement for transformation.
One-step examples for 2D transformation¶
- Translate \((2,3)\) by \((4,-1)\) to get \((6,2)\).
- Rotate \((1,0)\) by \(90^\circ\) counterclockwise to get \((0,1)\).
- If both endpoints of a line have left bit set in Cohen-Sutherland, the line is trivially rejected.
Two-dimensional-transformation revision box¶
Use homogeneous coordinates for all 2D transforms including translation. Order matters in composites. Cohen-Sutherland uses outcodes; Liang-Barsky uses parametric bounds. Window coordinates are mapped to a viewport after clipping.