Solved Numericals - Computer Graphics - CSU358

Solved Numericals

Q1. DDA Line from (3,2) to (11,7)

Given: $P_1(3,2), P_2(11,7)$

  1. Calculate Slope:
    $dx = 11 - 3 = 8$
    $dy = 7 - 2 = 5$
  2. Determine Steps:
    Since $|dx| > |dy|$ ($8 > 5$), $Steps = 8$.
  3. Calculate Increment:
    $X_{inc} = \frac{8}{8} = 1$
    $Y_{inc} = \frac{5}{8} = 0.625$
k X Y Plot (Round)
0 3 2 (3, 2)
1 4 2.625 (4, 3)
2 5 3.25 (5, 3)
3 6 3.875 (6, 4)
4 7 4.5 (7, 5)
5 8 5.125 (8, 5)
6 9 5.75 (9, 6)
7 10 6.375 (10, 6)
8 11 7.0 (11, 7)

Q2. DDA Line from (1,1) to (4,9)

Given: $P_1(1,1), P_2(4,9)$

  1. $dx = 4 - 1 = 3$
  2. $dy = 9 - 1 = 8$
  3. Since $|dy| > |dx|$, $Steps = 8$.
  4. $X_{inc} = \frac{3}{8} = 0.375$, $Y_{inc} = \frac{8}{8} = 1$.
k X Y Plot (Round)
0 1 1 (1, 1)
1 1.375 2 (1, 2)
2 1.75 3 (2, 3)
3 2.125 4 (2, 4)
4 2.5 5 (3, 5)
5 2.875 6 (3, 6)
6 3.25 7 (3, 7)
7 3.625 8 (4, 8)
8 4.0 9 (4, 9)

Q3. Bresenham Line from (2,3) to (12,8)

Given: $P_1(2,3), P_2(12,8)$

k $P_k$ Plot $(x_{k+1}, y_{k+1})$ Update Rule
0 0 (2, 3) Start
1 0 (3, 4) Since $P \ge 0$, Inc Both, $P = P - 10$ (-10)
2 -10 (4, 4) Since $P < 0$, Inc X, $P=P + 10$ (0)
3 0 (5, 5) Since $P \ge 0$, Inc Both, $P = -10$
4 -10 (6, 5) $P < 0$, Inc X, $P=0$
5 0 (7, 6) $P \ge 0$, Inc Both, $P=-10$
6 -10 (8, 6) $P < 0$, Inc X, $P=0$
7 0 (9, 7) $P \ge 0$, Inc Both, $P=-10$
8 -10 (10, 7) $P < 0$, Inc X, $P=0$
9 0 (11, 8) $P \ge 0$, Inc Both, end

Q4. Mid-Point Circle (r = 6) - First 8 Points

Constraint: Plot symmetric points.

Quadrant 1 Octant 2 Calculation (x starts at 0, y at r):

k $P_k$ Next Point $P_{k+1}$ Formula
0 -5 (1, 6) $P + 2x + 1 = -5 + 2(1) + 1 = -2$
1 -2 (2, 6) $P + 2x + 1 = -2 + 2(2) + 1 = 3$
2 3 (3, 5) $P + 2x - 2y + 1 = 3 + 6 - 10 + 1 = 0$
3 0 (4, 4) End ($x=y$)

The First 8 Symmetric Points (from (1,6)):

            mindmap
              root((Symmetry))
                Point (1,6)
                Review
                  (1, 6)
                  (6, 1)
                  (1, -6)
                  (6, -1)
                  (-1, 6)
                  (-6, 1)
                  (-1, -6)
                  (-6, -1)
            

Q5. Circle (r = 10) - First 5 Points

Start: $(0, 10)$, $P_0 = 1 - 10 = -9$.

Q6. Translate Triangle A(1,2), B(4,3), C(6,1)

Vector: $T_x = 2, T_y = 5$. Formula: $x' = x + T_x, y' = y + T_y$.

Q7. Scale Rectangle by $S_x=2, S_y=3$

Given: $P(2,2), Q(4,2), R(4,5), S(2,5)$. Formula: $x' = x \cdot S_x, y' = y \cdot S_y$.

Q8. Rotate Point (5,2) by 90°

About Origin:

$$x' = x \cos 90^\circ - y \sin 90^\circ = x(0) - y(1) = -y$$ $$y' = x \sin 90^\circ + y \cos 90^\circ = x(1) + y(0) = x$$

Substitution:

Q9. Rotate Triangle A(1,1), B(2,3), C(3,1) by 45°

$\cos 45^\circ = \sin 45^\circ = \frac{1}{\sqrt{2}} \approx 0.707$

Formulas:

Calculation:

Point Calculation Result (Approx)
A(1,1) $x' = 0.707(1-1) = 0$
$y' = 0.707(1+1) = 1.414$
$\mathbf{A'(0, 1.41)}$
B(2,3) $x' = 0.707(2-3) = -0.707$
$y' = 0.707(2+3) = 3.535$
$\mathbf{B'(-0.70, 3.53)}$
C(3,1) $x' = 0.707(3-1) = 1.414$
$y' = 0.707(3+1) = 2.828$
$\mathbf{C'(1.41, 2.82)}$

Q10. Reflect Point (4,5) in Y-axis

Concept: Mirroring across the vertical axis flips the X sign.

            graph LR
                A((4, 5)) -- "Reflect Y" --> B((\-4, 5))
            

Formula: $x' = -x, \quad y' = y$

Result: $\mathbf{(-4, 5)}$