Nothing in the world is more common than unsuccessful people with talent.
--Your friends at LectureNotes

Note for Computer Graphics - CG By Narendra Singh

  • Computer Graphics - CG
  • Note
  • VEL TECH ARTS college - veltech
  • Uploaded 2 months ago
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-1

SAZ4C – COMPUTER GRAPHICS UNIT – II Line-Drawing (DDA and Bresenham’s) Algorithms – Circle-Generating (Midpoint) Algorithm – Ellipse-Generating (Midpoint) Algorithms – Area-Filling (Boundary-Fill and Flood-Fill) Algorithms - Line Attributes - Color and Grayscale Levels – Character Attributes – Inquiry Functions . (I) LINE DRAWING ALGORITHMS Straight Line Equation in the form of Slope intercept is as follows: y = m x + b ------------1    where m represents the slope of the line and b as the y intercept which it makes with the Y axis. The two end point of a line segment are denoted by the positions (x1, y1) and (x2, y2) as shown in the following diagram. Using this Equation we can determine values for the slope m and y intercept b using the following calculations. The basic element of any graphics is a line which connects two points. For drawing a line two points are required. In the following different algorithms, one point of the line is referred as and the second point of the line is referred as 1

Text from page-2

A) DDA LINE ALGORITHMS DEFINITION: Equation Derivation: Sample the line at unit intervals in one coordinate and determine corresponding integer values nearest. The line paths for the other coordinate. Now consider first a line with positive slope, as shown below If the slope is less than one or equal to 1. We sample at unit x intervals (Δx = 1) compute each successive y values as : ALGORITHM Step 1 − Get the input of two end points and Step 2 – The difference between the two end points is calculated. dx = X1 - X0 dy = Y1 - Y0 Step 3 – On the basis of difference calculated, the number of steps that are needed to put in pixel need to be identified. If dx > dy, then more steps are required in x coordinate; otherwise in y coordinate. if (absolute(dx) > absolute(dy)) Steps = absolute(dx); else Steps = absolute(dy); Step 4 – The increment in the x coordinate and y coordinate are calculated. Xincrement = dx / (float) steps; Yincrement = dy / (float) steps; 2

Text from page-3

Step 5 – After successful implementation of x and y coordinates, put the pixel and complete the process of drawing the line. for(int v=0; v < Steps; v++) { x = x + Xincrement; y = y + Yincrement; putpixel(Round(x), Round(y)); } DDA Algorithm not good & efficient Algorithm? 1. DDA traces out the successive x & y values by simultaneously increasing x & y by small steps proportional to their first derivative. In our example the x increment is 1 but y increment is = m. since the real values have limited Precision, the accumulation of round off error in “m” causes the accumulative error. Build up which drifts the pixel positions from the true line path in most lines. dy dx 2. Moreover the round off operations & floating point incrementation is still time consuming. 3

Text from page-4

B) BRESENHAM’S LINE ALGORITHMS Another incremental scan conversion algorithm is Bresenham algorithm. The main advantage associated is that only integer calculations are used by this algorithm. In unit intervals, the line is moved across the x axis and at each step the y coordinates are chosen.  For instance, from position (2, 3) choose between (3, 3) and (3, 4). The point that is closer to the original line is preferred. From the above illustration, the y coordinate on the mathematical line at 4

Lecture Notes