Consider the midpoint (or Bresenham) algorithm for rasterizing lines given below:

(1) Input (x1, y1) and (x2, y2)

(2) y = y1

(3) d = f(x1 + 1, y1 + ½) / f is the implicit form of a line

(4) for x = x 1 to x 2

(5) do

(6) plot(x,y)

(7) if(d<0)

(8) then

(9) y = y + 1

(10) d = d + (y1 - y2) + (x2 - x1)

(11) else

(12) d = d + (y1 - y2)

(13) end

(14) end

Which statements are true?

P: For a line with slope m>1, we should change the outer loop in line (4) to 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.

This question was previously asked in
UGC NET Computer Science (Paper 2) Dec 2018 Paper
View all UGC NET Papers >
  1. Q and R only
  2. P only
  3. P and Q only
  4. P, Q and R

Answer (Detailed Solution Below)

Option 3 : P and Q only
Free
UGC NET Paper 1: Held on 21st August 2024 Shift 1
10.8 K Users
50 Questions 100 Marks 60 Mins

Detailed Solution

Download Solution PDF

Statement P: For a line with slope m>1, we should change the outer loop in line (4) to be over y.

Line 4) for x = x1 to x2 should be changed to be over y and slope m > 1

Slope of a line m = (y2 – y1)/ (x2 – x1). Because now it depends on x coordinates, to be over y it should depend on y coordinates.

Statement Q: Lines (10) and (12) update the decision variable d through an incremental evaluation of the line equation f.

It is clearly shown in the algorithm, that line (10) and line (12) are changing the values of d through incremental evaluation. i.e. adding d with itself.

d = d + (y1​ - y2) + (x2​ - x1)       ---- line (10)

d = d + (y1 - y2)                       ---- line (12)

R: The algorithm fails if d is ever 0

Algorithm does not fail when d is 0. because when d becomes greater than or equal to zero then it goes to line 12 and compute the value of. So, this statement is false.
Latest UGC NET Updates

Last updated on Jun 12, 2025

-> The UGC NET June 2025 exam will be conducted from 25th to 29th June 2025.

-> The UGC-NET exam takes place for 85 subjects, to determine the eligibility for 'Junior Research Fellowship’ and ‘Assistant Professor’ posts, as well as for PhD. admissions.

-> The exam is conducted bi-annually - in June and December cycles.

-> The exam comprises two papers - Paper I and Paper II. Paper I consists of 50 questions and Paper II consists of 100 questions. 

-> The candidates who are preparing for the exam can check the UGC NET Previous Year Papers and UGC NET Test Series to boost their preparations.

Get Free Access Now
Hot Links: online teen patti real money teen patti master golden india teen patti jodi teen patti tiger