Consider the midpoint (Bresenham) algorithm for rasterizing lines: (1) Input (x₁, y₁) and (x₂, y₂) (2) y = y₁ (3) d = f(x₁ + 1, y₁ + 1/2) // f is the implicit form of the line (4) for x = x₁ to x₂ (5) do (6) plot(x, y) (7) if (d < 0) (8) then (9) y = y + 1 (10) d = d + (y₁ − y₂) + (x₂ − x₁) (11) else (12) d = d + (y₁ − y₂) (13) end (14) end Which statements are true? P: For a line with slope m > 1, the outer loop in line (4) should be over y. Q: Lines (10) and (12) update the decision variable d through an incremental evaluation of the line equation f. R: The algorithm fails if d is ever 0.
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: B. P and Q only
Explanation
For steep lines the roles of x and y are swapped (P true). The updates add the change in f for a step in x or in x and y (Q true). d = 0 falls into the else branch, so nothing fails (R false).
More Programming Languages and Computer Graphics questions
- In 3D Graphics, which of the following statements about perspective and parallel projection is/are true? P : In a perspective projection, t…
- In 3D Graphics, which of the following statements is/are true? P : Back-face culling is an example of an image- precision visible-surface d…
- Consider the two C++ programs P1 and P2 shown below and two statements about them: S1: P1 prints out 3 S2: P2 prints out 4:2 What can you s…
- Consider the following recursive Java function f that takes two long arguments and returns a float value : public static float f(long m, lo…
- What does the following Java function perform? (Assume int occupies four bytes of storage) public static int f( int a) { // Pre-conditions…
- Which of the following HTML5 codes will affect the horizontal as well as vertical alignment of the table content?