Department of Information Technology Subject : Computer Graphics Lab (AY: 2019-20 Sem-2) Write-up Correctness of Program Documentation of Program Viva 2 2 2 2 Timely Completion 2 Total Dated Sign of Subject Teacher 10 Date of Performance:..................................... Expected Date of Completion:....................... Actual Date of Completion:.......................................... ---------------------------------------------------------------------------------------------------------------- Assignment No: 1 ---------------------------------------------------------------------------------------------------------------Title of the Assignment: Draw the following pattern using DDA Line drawing algorithms. ---------------------------------------------------------------------------------------------------------------Prerequisite: 1. Library function of OpenGL 2. Graphical Characteristics of line and Rectangle --------------------------------------------------------------------------------------------------------------Objective of the Assignment: To learn how to draw the above mentioned pattern using DDA Line Drawing Algorithm by taking the lower left and upper right point of the rectangle. --------------------------------------------------------------------------------------------------------------Outcomes: 1. Students should understand different equations of the line. 2. Students can able to identify the difference between different line generation algorithms. --------------------------------------------------------------------------------------------------------------Software & Hardware Requirements: Eclipse with Ubuntu Operating System and OpenGL Libraries. --------------------------------------------------------------------------------------------------------------- SNJB’s Late Sau. K B Jain College of Engineering, Chandwad Dist. Nashik, MS Department of Information Technology Subject : Computer Graphics Lab (AY: 2019-20 Sem-2) Theory: Scan Conversion: The process of representing continuous graphics object as a collection of discrete pixels is called Scan Conversion. For e.g a line is defined by its two end points & the line equation It is the responsibility of graphics system or the application program to convert each primitive from its geometric definition into a set of pixels that make up the primitive in image space. This conversion task is generally referred to as a scan conversion or rasterization. Line drawing algorithms The Process of turning ON the pixels for a line is called line generation. When we want to draw a line we have to make pixels on that line to ON condition. A line in Computer graphics typically refers to line segment, which is a portion of straight line that extends indefinitely in opposite direction. It is defined by its two end points & the slope intercepts equation for a line: y = mx + b where, m = Slope of the line b = the y intercept of a line The two endpoints of a line segment are specified at positions (x1,y1) and (x2,y2). We can determine the value for slope m & b intercept as m = y2-y1/x2-x1 And, b = y1 – mx1 For a given x interval Δx along a line, we can compute the corresponding y interval Δy from Δy = m Δx Similarly, we can obtain x interval Δx by Δy: Δx = Δy/m DDA Line Drawing Algorithm: 1. Start with starting and ending coordinates of the line:(x0, y0) and (x1, y1) 2. Color first pixel (round to nearest integer) SNJB’s Late Sau. K B Jain College of Engineering, Chandwad Dist. Nashik, MS Department of Information Technology Subject : Computer Graphics Lab (AY: 2019-20 Sem-2) 3. Calculate Dx, Dy (Dx=x1-x0, Dy=y1-y0) 4. Calculate numsteps 5. Suppose Dx> Dy (gentle slope) There will be Dx steps (# pixels to be colored) [numsteps = Dx] Value of x is incremented by one 6. Suppose Dx< Dy (steep slope) There will be Dy steps (# pixels to be colored) [numsteps = Dy] Value of y is incremented by one 7. Set x=x0, y=y0 8. At each step, increment x by (x1-x0)/numsteps, and increment y by (y1-y0)/numsteps Plot( x, y) 9. For each step, round off x and y to nearest integer, and color pixel Input: Two end points of the line. Output: Calculated intermediate points of line. Flowchart for DDA Line Drawing Algorithm: Draw flowchart for the algorithm Consider a line from (0,0) to (-5,5) . Use DDA algorithm to rasterize of line. Solve this Example Advantages and Disadvantage of DDA Line drawing Algorithm: Advantages of DDA Line drawing Algorithm 1. The DDA algorithm is a faster method for calculating pixel positions than direct use of line equation y = mx+b 2. Very easy to understand Disadvantage of DDA Line drawing Algorithm: 1. The rounding operation & floating point arithmetic are time consuming procedures. 2. The accumulation of round-off error in successive addition of floating point increment can cause the calculated pixel position to drift away from the true line path for long line segment. 1.6Conclusion: DDA algorithm is an incremental scan conversion method. Here calculations are performed at each step using the results from the preceding step. The characteristic of the DDA algorithm is to take unit steps along one coordinate and compute the corresponding values along the other coordinate. The unit steps are always along the coordinate of greatest change i.e. Dx or Dy. SNJB’s Late Sau. K B Jain College of Engineering, Chandwad Dist. Nashik, MS Department of Information Technology Subject : Computer Graphics Lab (AY: 2019-20 Sem-2) Practice Assignment: Draw the following pattern using a Bresenham’s Line drawing algorithms. Oral Questions: 1. What is the difference between DDA and Bresenham’s Line drawing algorithm? 2. What is the use of abs function in DDA Line drawing algorithm? 3. What is the equation to find slope of the line? 4. What do you mean by sharp slope and steep slope? 5. What will happen for DDA Line drawing algorithm if slope of the line is negative? 6. How to find midpoint of line? SNJB’s Late Sau. K B Jain College of Engineering, Chandwad Dist. Nashik, MS