Computer Graphics ยท Unit 3 ยท 5 hrs
Two-Dimensional Geometric Transformations
Exam-focused notes for Two-Dimensional Geometric Transformations (Computer Graphics, CSC214): what the TU syllabus asks and how it has actually been tested, with 12 solved past questions from this unit.
Two-Dimensional Geometric Transformations in short
Two-dimensional geometric transformations let a program move, resize and reorient objects instead of redrawing them from scratch. This chapter builds the transformation matrices, shows how homogeneous coordinates let them combine by simple matrix multiplication, and then covers the viewing pipeline and clipping algorithms that decide what part of a scene is actually visible.
What this unit covers
- Two-Dimensional translation, Rotation, Scaling, Reflection and Shearing
- Homogeneous Coordinate and 2D Composite Transformations
- Transformation between Co-ordinate Systems
- Two Dimensional Viewing: Viewing pipeline, Window to viewport coordinate transformation
- Clipping: Point, Lines(Cohen Sutherland line clipping, Liang-Barsky Line Clipping), Polygon Clipping(Sutherland Hodgeman polygon clipping)
Clipping
2081 ยท 10 marks
What is the major drawback of Sutherland Hodgeman Polygon Clipping Algorithm? Illustrate with a suitable example. Explain B-spline curve and its properties.[10]
Show solved answerHide answer
Sutherland-Hodgman Polygon Clipping: Major Drawback + B-Spline Curves
Part 1: Major Drawback of Sutherland-Hodgman Algorithm
The Algorithm (Brief Recap)
The Sutherland-Hodgman algorithm clips a polygon against each edge of the rectangular clipping window one at a time. It processes the polygon vertex list against:
- Left boundary
- Right boundary
- Bottom boundary
- Top boundary
The four inside-outside cases for each edge are:
- Out โ In: Add intersection point V' and Vi+1
- In โ In: Add Vi+1
- In โ Out: Add intersection point V' only
- Out โ Out: Add nothing
Major Drawback: Incorrect Clipping of Concave (Non-Convex) Polygons
The Sutherland-Hodgman algorithm works correctly only for convex polygons. When applied to concave (non-convex) polygons, it produces incorrect results by generating spurious (extra, unwanted) edges that do not belong to the actual clipped polygon.
When a concave polygon is clipped, the algorithm may connect vertices that should not be connected, producing a polygon with extra edges crossing through the exterior region. The output polygon may appear distorted or have additional triangular/spurious regions.
Illustration with Example
Consider a concave (non-convex) polygon with vertices:
V1(10, 40), V2(40, 80), V3(70, 40), V4(40, 60)
This polygon is concave (the vertex V4 is indented inward, creating a "dent").
Clipping Window: Xmin=20, Ymin=30, Xmax=60, Ymax=70
V2(40,80)
/ \
V1(10,40) V3(70,40)
\ /
V4(40,60) <-- concave indentation
What should happen (correct result): The clipping should produce two separate polygon regions (two disjoint pieces) after clipping against the window boundaries, because the concave polygon, when clipped, naturally splits into two parts.
What Sutherland-Hodgman produces (incorrect result): Instead of two separate polygons, the algorithm connects the two separate pieces with a spurious edge along the clipping boundary, producing one single (incorrect) polygon with an extra edge that runs along the window boundary where no actual polygon edge exists.
Correct Output: S-H Output (Incorrect):
[Piece 1] [Piece 2] [Single polygon with
spurious connecting edge]
Diagram:
___________
| /\ |
| / \ | <-- Correct: two separate triangular regions
| / \ |
|_/______\__|
___________
| /\ |
| / \ | <-- S-H Output: spurious edge connects
| /____\ | the two regions incorrectly
|___________|
The spurious edge appears along the clipping boundary, connecting two intersection points that should not be connected. This creates a filled region that does not actually belong to the original polygon.
Summary of Drawback
| Aspect | Detail |
|---|---|
| Problem | Incorrect output for concave polygons |
| Cause | Algorithm cannot detect when clipped regions should be separate |
| Effect | Spurious/extra edges appear along clipping boundary |
| Solution | Use Weiler-Atherton Algorithm, which correctly handles concave polygons |
Part 2: B-Spline Curve and Its Properties
Definition
A B-spline curve (Basis spline curve) is a piecewise polynomial curve defined by a set of control points (polygon vertices) and a set of basis functions called B-spline basis functions. Unlike Bezier curves, B-spline curves provide local control over the shape of the curve.
The general equation of a B-spline curve is:
$$P(t) = \sum_{i=0}^{n} P_i \cdot N_{i,k}(t)$$
Where:
- $P_i$ = control points (i = 0, 1, 2, ..., n)
- $N_{i,k}(t)$ = B-spline basis functions of order k
- $k$ = order of the curve (degree = k - 1)
- $t$ = parameter value
B-Spline Basis Functions (Cox-de Boor Recursion)
The basis functions are defined recursively:
Order 1 (k=1): $$N_{i,1}(t) = \begin{cases} 1 & \text{if } t_i \leq t < t_{i+1} \ 0 & \text{otherwise} \end{cases}$$
Higher orders: $$N_{i,k}(t) = \frac{t - t_i}{t_{i+k-1} - t_i} N_{i,k-1}(t) + \frac{t_{i+k} - t}{t_{i+k} - t_{i+1}} N_{i+1,k-1}(t)$$
Where $t_i$ are the knot values forming the knot vector.
Example from Notes
Construct a B-spline curve of order 4 with 4 polygon vertices:
- A(1,1), B(2,3), C(4,3), D(6,2)
Given: n = 3 (4 control points: P0, P1, P2, P3), k = 4 (order 4)
Knot vector for uniform B-spline with n=3, k=4: Number of knots = n + k + 1 = 3 + 4 + 1 = 8
Uniform knot vector: T = {0, 0, 0, 0, 1, 1, 1, 1}
The knot value 0 is repeated k = 4 times at the start and 1 is repeated k = 4 times at the end (a clamped/open uniform knot vector). Since n - k + 2 = 3 - 4 + 2 = 1, there are no interior knot spans, so the curve reduces to a single Bezier-like segment defined over t โ [0, 1] that passes through the first and last control points, A(1,1) and D(6,2).
Properties of B-Spline Curves
- Local Control: Moving one control point $P_i$ only affects the portion of the curve where its basis function $N_{i,k}(t)$ is non-zero, unlike a Bezier curve where every control point influences the entire curve.
- Degree Independent of Control Points: The degree of a B-spline curve (k - 1) can be chosen independently of the number of control points, whereas a Bezier curve's degree is always (n) for n+1 control points.
- Convex Hull Property: The curve lies within the union of the convex hulls of each successive group of k control points.
- Continuity: A B-spline curve is $C^{k-2}$ continuous at simple (non-repeated) interior knots, allowing smoother joins between segments.
- Variation Diminishing Property: The curve does not oscillate more than its defining control polygon.
2080 ยท 10 marks
Why Liang Barsky Line Clipping Algorithm is efficient than Cohen Sutherland Algorithm? Explain the clipping procedure of Liang Barsky algorithm with suitable example.[10]
2079 ยท 10 marks
Write the algorithm for Cohen-Sutherland Line clipping. Clip the polygon A(100,150), B(200,250) and C(300,200) with the clipping window defined by the coordinates (100,300), (300,300) and (200,100) using Sutherland Hodgeman Polygon Clipping algorithm.[10]
Show solved answerHide answer
Cohen-Sutherland Line Clipping Algorithm and Sutherland-Hodgeman Polygon Clipping
Given
Polygon vertices:
- $A(100, 150)$
- $B(200, 250)$
- $C(300, 200)$
Clipping window (triangular) vertices:
- $W_1(100, 300)$
- $W_2(300, 300)$
- $W_3(200, 100)$
Task: State Cohen-Sutherland line clipping algorithm; clip triangle ABC against triangular window using Sutherland-Hodgeman.
Solution
Part 1: Cohen-Sutherland Line Clipping Algorithm
The clipping window divides the plane into 9 regions, each with a 4-bit outcode:
1001 | 1000 | 1010
-----+------+-----
0001 | 0000 | 0010
-----+------+-----
0101 | 0100 | 0110
Bit assignments (from left): Top ($y>y_{max}$), Bottom ($y<y_{min}$), Right ($x>x_{max}$), Left ($x<x_{min}$).
Algorithm:
- For endpoints $P_1(x_1,y_1)$, $P_2(x_2,y_2)$, compute their 4-bit outcodes.
- Trivial accept: if $\text{code}(P_1)\ \text{OR}\ \text{code}(P_2)=0000$, draw the whole line.
- Trivial reject: if $\text{code}(P_1)\ \text{AND}\ \text{code}(P_2)\neq 0000$, discard the line.
- Otherwise: pick an endpoint with a nonzero outcode, compute its intersection with the corresponding window boundary:
- Left: $y=y_1+m(x_{min}-x_1),\ x=x_{min}$
- Right: $y=y_1+m(x_{max}-x_1),\ x=x_{max}$
- Bottom: $x=x_1+\tfrac{1}{m}(y_{min}-y_1),\ y=y_{min}$
- Top: $x=x_1+\tfrac{1}{m}(y_{max}-y_1),\ y=y_{max}$
- Replace the outside endpoint with the intersection point, recompute its outcode, and repeat from step 2 until accept or reject.
Part 2: Sutherland-Hodgeman Polygon Clipping
Window edges (traversed so interior lies to the left):
Verify orientation. Vertices $W_1(100,300),W_2(300,300),W_3(200,100)$. The centroid is $\left(\tfrac{100+300+200}{3},\tfrac{300+300+100}{3}\right)=(200,\ 233.3)$.
Inside test: For directed edge $W_a\to W_b$, point $P$ is inside if $$f(P)=(x_b-x_a)(y_p-y_a)-(y_b-y_a)(x_p-x_a)\ge 0.$$
Check orientation using centroid for each edge; adjust sign so centroid is inside.
Edge 1: $W_1(100,300)\to W_2(300,300)$
$f(P)=(300-100)(y_p-300)-(300-300)(x_p-100)=200(y_p-300)$
Centroid: $200(233.3-300)<0$. So centroid gives negative; inside means $f(P)\le 0$, i.e. $y_p\le 300$.
| Vertex | $y_p$ | $y\le300$? |
|---|---|---|
| A(100,150) | 150 | Inside |
| B(200,250) | 250 | Inside |
| C(300,200) | 200 | Inside |
All inside. Output list I: A(100,150), B(200,250), C(300,200)
Edge 2: $W_2(300,300)\to W_3(200,100)$
$f(P)=(200-300)(y_p-300)-(100-300)(x_p-300)$ $=-100(y_p-300)+200(x_p-300)$
Centroid $(200,233.3)$: $-100(-66.7)+200(-100)=6670-20000=-13330<0$. So inside means $f(P)\le 0$.
Compute for each vertex of list I:
- A(100,150): $-100(150-300)+200(100-300)=15000-40000=-25000\le0$ โ Inside
- B(200,250): $-100(250-300)+200(200-300)=5000-20000=-15000\le0$ โ Inside
- C(300,200): $-100(200-300)+200(300-300)=10000+0=+10000>0$ โ Outside
Process pairs of list I (AโBโCโA):
A(in)โB(in): add B. B(in)โC(out): add intersection of BC with edge 2.
Line B(200,250)โC(300,200): parametric $x=200+100t,\ y=250-50t$. Edge 2 line: through (300,300) and (200,100): direction $(-100,-200)$, i.e. slope $2$, line $y-300=2(x-300)\Rightarrow y=2x-300$.
Substitute: $250-50t=2(200+100t)-300=100+200t$ $250-50t=100+200t\Rightarrow150=250t\Rightarrow t=0.6$ $x=200+60=260,\ y=250-30=220$. โ Intersection $P_1(260,220)$. Add $P_1$.
C(out)โA(in): add intersection of CA with edge 2, then add A.
Line C(300,200)โA(100,150): $x=300-200t,\ y=200-50t$. Into $y=2x-300$: $200-50t=2(300-200t)-300=300-400t$ $200-50t=300-400t\Rightarrow350t=100\Rightarrow t=0.2857$ $x=300-57.14=242.86,\ y=200-14.29=185.71$. โ $P_2(242.86,185.71)$. Add $P_2$, then A.
Output list II: B(200,250), $P_1$(260,220), $P_2$(242.86,185.71), A(100,150)
Edge 3: $W_3(200,100)\to W_1(100,300)$
$f(P)=(100-200)(y_p-100)-(300-100)(x_p-200)$ $=-100(y_p-100)-200(x_p-200)$
Centroid: $-100(133.3)-200(0)=-13330<0$. Inside means $f(P)\le 0$.
Check list II:
- B(200,250): $-100(150)-200(0)=-15000\le0$ โ Inside
- $P_1$(260,220): $-100(120)-200(60)=-12000-12000=-24000\le0$ โ Inside
- $P_2$(242.86,185.71): $-100(85.71)-200(42.86)=-8571-8572=-17143\le0$ โ Inside
- A(100,150): $-100(50)-200(-100)=-5000+20000=+15000>0$ โ Outside
Process pairs (Bโ$P_1$โ$P_2$โAโB):
B(in)โ$P_1$(in): add $P_1$ $P_1$(in)โ$P_2$(in): add $P_2$ $P_2$(in)โA(out): add intersection of $P_2$A with edge 3.
Edge 3 line through (200,100),(100,300): slope $=\tfrac{300-100}{100-200}=-2$, line $y-100=-2(x-200)\Rightarrow y=-2x+500$. Line $P_2(242.86,185.71)\to A(100,150)$: $x=242.86-142.86t,\ y=185.71-35.71t$. $185.71-35.71t=-2(242.86-142.86t)+500=-485.72+285.72t+500=14.28+285.72t$ $185.71-14.28=285.72t+35.71t\Rightarrow171.43=321.43t\Rightarrow t=0.5333$ $x=242.86-76.19=166.67,\ y=185.71-19.05=166.67$. โ $P_3(166.67,166.67)$. Add $P_3$.
A(out)โB(in): add intersection of AB with edge 3, then add B. Line A(100,150)โB(200,250): $x=100+100t,\ y=150+100t$. Into $y=-2x+500$: $150+100t=-2(100+100t)+500=300-200t$ $150+100t=300-200t\Rightarrow300t=150\Rightarrow t=0.5$ $x=150,\ y=200$. โ $P_4(150,200)$. Add $P_4$, then B.
Final Clipped Polygon
Vertices: $$P_1(260,220),\ P_2(242.86,185.71),\ P_3(166.67,166.67),\ P_4(150,200),\ B(200,250)$$
2077 ยท 5 marks
Let ABCD be the rectangle window with A(0, 0), B(10, 0), C(10, 10) and D(0, 10). Use Liang Barsky line clipping algorithm to clip the line XY where X(5, 3) and Y(15, 9). [5]
2075 ยท 10 marks
Define window, viewport and viewing transformation. Let ABCD be the regular window with A(20, 20), B(90, 20), C(90, 70), and D(20, 70). Find the region codes for end points and use Cohen Sutherland algorithm to clip the lines P(10, 30) Q(80, 90).[10]
Show solved answerHide answer
Window, Viewport, Viewing Transformation and Cohen-Sutherland Clipping
Part 1: Definitions
Window: A rectangular region defined in the world coordinate system that selects the portion of a scene to be displayed. Only objects lying inside the window are shown.
Viewport: A rectangular region on the display device (screen, in device/normalized coordinates) onto which the contents of the window are mapped.
Viewing Transformation: The mapping of the contents of a window in world coordinates to a viewport on the display device, also called the window-to-viewport transformation. Composite form:
$$T_{wv} = T(xv_{min}, yv_{min}) \cdot S(S_x, S_y) \cdot T(-xw_{min}, -yw_{min})$$
$$S_x = \frac{xv_{max}-xv_{min}}{xw_{max}-xw_{min}}, \qquad S_y = \frac{yv_{max}-yv_{min}}{yw_{max}-yw_{min}}$$
Part 2: Cohen-Sutherland Line Clipping
Given Data
Window ABCD: A(20,20), B(90,20), C(90,70), D(20,70)
$$x_{min}=20,\quad x_{max}=90,\quad y_{min}=20,\quad y_{max}=70$$
Line: $P(10,30)$ to $Q(80,90)$
Region Code (Top | Bottom | Right | Left)
csc214-outcode-regions
P(10, 30):
- Top: $30>70$? No โ 0
- Bottom: $30<20$? No โ 0
- Right: $10>90$? No โ 0
- Left: $10<20$? Yes โ 1
$$\text{Code}(P) = 0001$$
Q(80, 90):
- Top: $90>70$? Yes โ 1
- Bottom: $90<20$? No โ 0
- Right: $80>90$? No โ 0
- Left: $80<20$? No โ 0
$$\text{Code}(Q) = 1000$$
Trivial Tests
- AND: $0001 \text{ AND } 1000 = 0000$ โ not trivially rejected
- OR: $0001 \text{ OR } 1000 = 1001 \ne 0000$ โ not trivially accepted
Line must be clipped. Slope quantities: $$\Delta x = 80-10 = 70, \qquad \Delta y = 90-30 = 60$$ $$m = \frac{\Delta y}{\Delta x} = \frac{60}{70} = \frac{6}{7}$$
Clip Point P (code 0001, Left boundary x = 20)
$$y = y_1 + m(x_{min}-x_1) = 30 + \frac{6}{7}(20-10) = 30 + \frac{60}{7} = 38.57$$
New point $P' = (20, 38.57)$
Code of $P'(20, 38.57)$: Top no, Bottom no, Right no, Left ($20<20$? no) โ 0000 (inside)
Clip Point Q (code 1000, Top boundary y = 70)
$$x = x_1 + \frac{1}{m}(y_{max}-y_1) = 10 + \frac{7}{6}(70-30) = 10 + \frac{7}{6}\times 40$$ $$x = 10 + 46.67 = 56.67$$
New point $Q' = (56.67, 70)$
Code of $Q'(56.67, 70)$: Top ($70>70$? no) โ 0, Bottom no, Right ($56.67>90$? no) โ 0, Left no โ 0000 (inside)
Final Result
Both endpoints now have code 0000 โ line accepted.
$$\boxed{\text{Clipped line: } P'(20,\ 38.57) \text{ to } Q'(56.67,\ 70)}$$
The complete result requires clipping $Q$ as well, giving $Q'(56.67, 70)$.
2075 ยท 5 marks
Define clipping. Discuss about cubic spline Interpolation. [5]
Homogeneous Coordinate and 2D Composite Transformations
2081 ยท 5 marks
Given a triangle with vertices A(2,3), B(5,5), C(4,3) by rotating 90 degrees about the origin and then translating two units in each direction. Use the homogeneous transformation matrix to find the new vertices of the triangle. [5]
2079 ยท 5 marks
Find the composite transformation matrix for reflection about a line y=mx+c. [5]
Two-Dimensional translation, Rotation, Scaling, Reflection and Shearing
2080 ยท 5 marks
Reflect a line segment having end points (9,3) and (12,10) about a line X=7. Draw initial and final result graph as well. [5]
2079 ยท 5 marks
Reflect a line segment having endpoints (9,3) and (12,10) about a line Y=7. Draw initial and final result graph as well. [5]
2078 ยท 5 marks
Find the new c-coordinate of the triangle ABC, with co-ordinates A(0, 0), B(1, 1) and C(5, 2) after it has been magnified to twice of its size. [5]
2077 ยท 5 marks
Translate a triangle ABC with co-ordinates A(0, 0), B(5, 0) and C(5, 5) by 2 units in x-direction and 3 units in y-directions. [5]
Make Unit 3 stick
Practice CSC214 with flashcards & quizzes