Computer Graphics : output primitives.. 2 of 32 T1 – pp. 103–123, 137–145, 147–150, 164–171 Points and LinesPoints Line Drawing AlgorithmsLine Mid–Point.

Slides:



Advertisements
Similar presentations
Line Drawing Algorithms
Advertisements

Graphics Primitives: line
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Drawing Elementary Figures Dr. Eng. Farag Elnagahy.
Line Drawing Algorithms
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Lecture 5 Rendering lines 1.Steps of line rendering 2.Scan-conversion for line segments 3.A1 tutorial CP411 Computer Graphics Fall 2007 Wilfrid Laurier.
Scan Conversion Algorithms
Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing.
Larry F. Hodges (modified by Amos Johnson) 1 Design of Line, Circle & Ellipse Algorithms.
30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
The lines of this object appear continuous However, they are made of pixels 2April 13, 2015.
Raster conversion algorithms for line and circle
Output Primitives Computer Graphics.
Course Website: Computer Graphics 5: Line Drawing Algorithms.
Line Drawing by Algorithm. Line Drawing Algorithms Line drawn as pixels Graphics system –Projects the endpoints to their pixel locations in the frame.
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
Dr. S.M. Malaek Assistant: M. Younesi
Graphics Primitives: line. Pixel Position
WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition.
Scan Conversion Line and Circle
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
Larry F. Hodges 1 Design of Line and Circle Algorithms.
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
Graphics Output Primitives
Line Drawing and Generalization. Outline  overview  line drawing  circle drawing  curve drawing.
CGMB214: Introduction to Computer Graphics
 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
CS-321 Dr. Mark L. Hornick 1 Line Drawing Algorithms.
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
In the name of God Computer Graphics. Today Introduction Sampling Graphic Output Primitives 1.Line 2.Circle 3.Curve 4.polygon.
Raster graphics & Line Drawing Algorithms Kaushik.S VIT
Rendering.
Lecture 13: Raster Graphics and Scan Conversion
Bresenham’s Line Algorithm
OUTPUT PRIMITIVES A.Aruna/Faculty of Information technology/SNSCE13/19/2016.
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas CS- 375 Graphics and Human Computer Interaction.
Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Scan Conversion of Line Segments. What is Scan conversion? Final step of rasterization (the process of taking geometric shapes and converting them into.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
Line Drawing Algorithms 1. A line in Computer graphics is a portion of straight line that extends indefinitely in opposite direction. 2. It is defined.
Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.
Primitive graphic objects
Line Drawing Algorithms
Scan Conversion or Rasterization
CSCE 441 Lecture 2: Scan Conversion of Lines
Raster Graphics.
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Scan Conversion or Rasterization
Lecture 8 Shear and Line Drawing Algorithms
Chapter Three Part I Output Primitives CS 380.
Computer Graphics 5: Line Drawing Algorithms
Computer Graphics 5: Line Drawing Algorithms
CSCE 441 Lecture 2: Scan Conversion of Lines
Allah says Say, "Allah created cattle for you. In them you find warmth and benefit and from them you eat. In them there is beauty for you when you bring.
Rasterization and Antialiasing
Computer Graphics 5: Line Drawing Algorithms
Rasterization and Antialiasing
Chapter 3 Graphics Output Primitives
Line Drawing Algorithms
OUTPUT PRIMITIVES / DISPLAY TECHNIQUES
Presentation transcript:

Computer Graphics : output primitives.

2 of 32 T1 – pp. 103–123, 137–145, 147–150, 164–171 Points and LinesPoints Line Drawing AlgorithmsLine Mid–Point Circle AlgorithmCircle Ellipse AlgorithmEllipse Character GenerationGeneration University Exam University Exam Questions Dr. DSR Murthy2Unit II: Output Primitives UNIT I: Output Primitives

3 of 32 Dr. DSR Murthy3Unit II: Output Primitives Points and Lines

4 of 32 Dr. DSR Murthy4Unit II: Output Primitives Points and Lines

5 of 32 Dr. DSR Murthy5Unit II: Output Primitives Pixel Picture element. Smallest Addressable Screen element. Each pixel has a Name or Address. Computer Graphics images are made by setting the intensity and colour of the pixels composing the screen. Display Screen is a Grid or Array of pixels. The coordinate (i, j) will give the Col. and Row of a Pixel. Each pixel will be centred at its Coordinates.

6 of 32 Dr. DSR Murthy6Unit II: Output Primitives Resolution Maximum no. of Distinguishable points, which a line may have, is a Measure of the Resolution of the Display Device. Greater the no. of Points, Higher the Resolution.

7 of 32 The Problem Of Scan Conversion A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)

8 of 32 The Problem (cont…) But what happens when we try to draw this on a pixel based display? How do we choose which pixels to turn on?

9 of 32 Considerations Considerations to keep in mind: –The line has to look good Avoid jaggies –It has to be lightening fast! How many lines need to be drawn in a typical scene? This is going to come back to bite us again and again

10 of 32 Line Equations x y y0y0 y end x end x0x0 Slope-intercept line equation: where:

11 of 32 For any given x intervals dx along a line, we can compute the corresponding y if interval dY from eqn dy=m dx Similarly, we can obtain the x interval dx corresponding to a specified dy as dx = dy/m

12 of 32 A Very Simple Solution (cont…) Slant Slope Case Sharp Slope Case IF M>1 IF M<1

13 of 32 Increment of x or y depends on slope If m>1, increment y and find x dy can be set propos ional to a small vertical deflection voltage and the corresponding horizontal deflection voltage set propos ional to dx as calculated from eqn. Slant Slope Case: If m<1, increment x and find y dx can be set proposional to a small horizontal deflection voltage and the corresponding vertical deflection voltage set propos ional to dy as calculated from eqn If m=1, dx=dy and horizontal and vertical deflections voltages are equal. Sharp Slope Case:

14 of 32 Lines & Slopes The slope of a line ( m ) is defined by its start and end coordinates The diagram below shows some examples of lines and their slopes m = 0 m = - 1 / 3 m = - 1 / 2 m = -1 m = -2 m = -4 m = ∞ m = 1 / 3 m = 1 / 2 m = 1 m = 2 m = 4 m = 0

15 of 32 A Very Simple Solution We could simply work out the corresponding y coordinate for each unit x coordinate Let’s consider the following example: x y (2, 2) (7, 5)

16 of 32 A Very Simple Solution (cont…) x y (2, 2) (7, 5) LINE EQUATION : y= mx+b First work out m and b : Now for each x value work out the y value:

17 of 32 A Very Simple Solution (cont…) Now just round off the results and turn on these pixels to draw our line

18 of 32 A Very Simple Solution (cont…) However, this approach is just way too slow In particular look out for: –The equation y = mx + b requires the multiplication of m by x –Rounding off the resulting y coordinates We need a faster solution

19 of 32 A Quick Note About Slopes In the previous example we chose to solve the parametric line equation to give us the y coordinate for each unit x coordinate What if we had done it the other way around? So this gives us: where: and If m>1, increment y and find x If m≤1, increment x and find y

20 of 32 A Quick Note About Slopes (cont…) Leaving out the details this gives us: We can see easily that this line doesn’t look very good! We choose which way to work out the line pixels based on the slope of the line

21 of 32 A Quick Note About Slopes (cont…) If the slope of a line is between -1 and 1 then we work out the y coordinates for a line based on it’s unit x coordinates Otherwise we do the opposite – x coordinates are computed based on unit y coordinates m = 0 m = - 1 / 3 m = - 1 / 2 m = -1 m = -2 m = -4 m = ∞ m = 1 / 3 m = 1 / 2 m = 1 m = 2 m = 4 m = 0

22 of 32 A Quick Note About Slopes (cont…)

23 of 32 The DDA Algorithm The digital differential analyzer (DDA) algorithm takes an incremental approach in order to speed up scan conversion Simply calculate y k+1 based on y k The original differential analyzer was a physical machine developed by Vannevar Bush at MIT in the 1930’s in order to solve ordinary differential equations.

24 of 32 Calculating the Values of ‘x’ and ‘y’ Step 1: For lines whose slope is positive and is less than or equal to 1 (m≤1) These lines can be sampled at ‘x’ intervals i.e., x = 1 and the corresponding ‘y’ values can be calculated using, Y k+1 = Y k + m Where, ‘k’ takes the integer values starting from 1 and its value is successfully incremented, till the last point is reached and the slope ‘m’ can either ‘0’ or’1’. Step 2: For lines whose slope is positive and is greater than 1 (m>1) These lines can be sampled at unit ‘y’ intervals i.e., y = 1 and the corresponding ‘x’ values can be determined as, x k+1 = x k / m Line processing starts from left to right. If the first end point is at right then. y k+1 = y k - m and x k+1 = x k / m

25 of 32 DDA algorithm Step 1: Read the 2 end points (x1,y1), (x2,y2) Step 2: Horizontal and vertical differences between the end points positions are assigned to parameters dx and dy. dx=x2-x1 dy=y2-y1 Step 3: The difference with the greater magnitude determines the value of parameter steps If (abs(dx)> abs(dy)) then steps = abs(dx) // Slant slope case Else steps = abs(dy) // Sharp slope case Step 4: Starting with pixel positions (x1,y1) and we determine the offset needed at each step to generate the next pixel position along the line path. X increment = dx/ steps Y increment = dy/ steps Step 5: Assign the values of x1, y1 to x,y respectively x=x1y=y1 Step 6: Plot the point at (x,y) positions on screen set pixel (round(x),round(y),1). Here 1 is the intensity of pixel i.e, intensity with which picture illuminated. Step 7: Calculate the values of x and y for next pixel position X= x+Xincrement Y= y+ Yincrement Step 8: Plot the pixel at (x,y) position, set pixel(round(x),round(y),1). Step 9: repeat the steps 7 and 8 until steps=0.

26 of 32 DDA Algorithm

27 of 32 DDA ALGORITHM #define round(a) (int (a+0.5)) Procedure linDDA( xa, xb, ya, yb : integer); Var dx, dy, steps, k : integer; Xincrement, Yincrement, x,y :real; Begin dx = xb-xa; dx, dy calculations dy= yb-ya; If abs(dx) > abs(dy) then steps = abs(dx); Else steps = abs(dy); deciding slant slope or sharp slope ∆x = dx /steps; finding ∆x, ∆y ∆y = dy / steps; x=xa; y=ya; Setpixel (round (x), round (y),1); For k=1 to steps do Begin x= x+ ∆x ; y= y+ ∆y; Setpixel ( round(x), round(y),1); End; Turning on all the pixels in b/w given points (xa,ya), (xb,yb) initializing x,y to xa,ya and turning on that pixel

28 of 32 DDA Algorithm. The following is thus the basic incremental scan-conversion (DDA) algorithm for line drawing for x from x0 to x1 Compute y=mx+b Draw_fn(x, round(y))

29 of 32 DDA Example Suppose we want to draw a line starting at pixel (2,3) and ending at pixel (12,8). What are the values of the variables x and y at each timestep? What are the pixels colored, according to the DDA algorithm? numsteps = 12 – 2 = 10 xinc = 10/10 = 1.0 yinc = 5/10 = 0.5 txyR(x)R(y)

30 of 32 DDA Algorithm Example Let’s try out the following examples: x y (2, 2) (7, 5) x y (2, 7) (3, 2)

31 of 32 DDA Algorithm Example (cont…)

32 of 32 Advantages of DDA It calculates the pixel positions faster than the calculations performed by using the equation y=mx +b. Multiplication is eliminated as the x and y increments are used to determine the position of the next pixel on a line

33 of 32 Disadvantages of DDA The rounding and floating point operations are time consuming. The round-off error which results in each successive addition leads to the drift in pixel position, already calculated

34 of 32 The DDA Algorithm Summary The DDA algorithm is much faster than our previous attempt –In particular, there are no longer any multiplications involved However, there are still two big issues: –Accumulation of round-off errors can make the pixelated line drift away from what was intended –The rounding operations and floating point arithmetic involved are time consuming

35 of 32 Conclusion Drawing lines to pixel based displays is time consuming so we need good ways to do it The DDA algorithm is pretty good – but we can do better Next time we’ll like at the Bresenham’s line algorithm and how to draw circles, fill polygons and anti-aliasing