Computer Graphics Lecture 05 Line Drawing Techniques Taqdees A. Siddiqi

Slides:



Advertisements
Similar presentations
Graphics Primitives: line
Advertisements

5.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 5 – Drawing A Line.
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
Section 3-1 to 3-2, 3-5 Drawing Lines Some of the material in these slides may have been adapted from university of Virginia, MIT, and Åbo Akademi University.
CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
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.
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
Scan conversion of Line , circle & ellipse
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.
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
Raster conversion algorithms for line and circle
Output Primitives Computer Graphics.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007.
University of Missouri at Columbia 2D Scan-line Conversion University of Missouri at Columbia.
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.
Circle Drawing algo..
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Scan Conversion. Also known as rasterization In our programs objects are represented symbolically –3D coordinates representing an object’s position –Attributes.
Dr. S.M. Malaek Assistant: M. Younesi
1 CPE 333 : Computer Graphics มหาวิทยาลัยเทคโนโลยีพระจอม เกล้าธนบุรี Dr. Natasha Dejdumrong.
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.
CS 325 Introduction to Computer Graphics 02 / 01 / 2010 Instructor: Michael Eckmann.
1Computer Graphics Implementation III Lecture 17 John Shearer Culture Lab – space 2
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)
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.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
Week 4 Functions and Graphs. Objectives At the end of this session, you will be able to: Define and compute slope of a line. Write the point-slope equation.
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.
Write Bresenham’s algorithm for generation of line also indicate which raster locations would be chosen by Bresenham’s algorithm when scan converting.
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Computer Graphics Lecture 07 Ellipse and Other Curves Taqdees A. Siddiqi
Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi
Scan Conversion of Line Segments. What is Scan conversion? Final step of rasterization (the process of taking geometric shapes and converting them into.
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.
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
Computer Graphics Lecture 13 Graphics Systems Taqdees A
Lecture 9 Line Drawing Algorithms (Bresenham’s Line Algorithm)
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Lecture 8 Shear and Line Drawing Algorithms
Chapter Three Part I Output Primitives CS 380.
2D Scan-line Conversion
Computer Graphics Lecture 20
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Rasterization and Antialiasing
Rasterization and Antialiasing
Edited from The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.
Chapter 3 Graphics Output Primitives
Where We Stand At this point we know how to: Next thing:
S.JOSEPHINE THERESA, DEPT OF CS, SJC, TRICHY-2
Line Drawing Algorithms
Presentation transcript:

Computer Graphics Lecture 05 Line Drawing Techniques Taqdees A. Siddiqi

What is Line A line, or straight line, is, roughly speaking, (infinitely) thin, (infinitely) long, straight geometrical object, i.e. a curve that is long and straight.

Line Cont… Given two points, in Euclidean geometry, one can always find exactly one line that passes through the two points.

Line Cont… A line may have three forms with respect to slope:  slope = 1  slope > 1  slope < 1

Line Cont… figure (a) figure (b) figure (c)

Line Drawing Techniques There are three techniques to be discussed to draw a line involving different time complexities that will be discussed along. These techniques are:  Incremental line algorithm  DDA line algorithm  Bresenham line algorithm

Incremental Line Algorithm This algorithm exploits simple line equation y = m x + b where m = dy / dx andb = y – m x

now check if |m| < 1 then x = x + 1whereas y = m x + b

why to check |m| suppose a line has points p1 (10, 10) – p2 (20, 18) dy = y2 – y1 = 18 – 10 = 8 dx = x2 – x1 = 20 – 10 = 10

This means that there will be 10 pixels on the line in which for x-axis there will be distance of 1 between each pixel and for y-axis the distance will be 0.8.

Now consider the reverse case suppose a line has points p1 (10, 10), p2 (16, 20) dy = y2 – y1 = 20 – 10 = 10 dx = x2 – x1 = 16 – 10 = 6

This means that there will be 10 pixels on the line in which for x-axis there will be distance of 0.6 between each pixel and for y-axis the distance will be 1.

Now sum-up all discussion in algorithm to fully understand. The algorithm will take two points P1 and P2 and draw line between them whereas each point consists of x,y coordinates.

dx = p2.x – p1. x dy = p2.y – p1. y m = dy / dx x = p1.x y = p1.y b = y – m * x

if |m| < 1 for counter = p1.x to p2.x drawPixel (x, y) x = x + 1 y = m * x + b else for counter = p1.y to p2.y drawPixel (x, y) y = y + 1 x = ( y – b ) / m

Discussion on algorithm:  quite simple and easy to understand  but involves a lot of mathematical calculations 24

We have another algorithm that works fine in all directions and involves less calculations; mostly only additions.

DDA Algorithm DDA abbreviated for digital differential analyzer has a very simple technique. Find difference, dx and dy as: dy = y2 – y1 dx = x2 – x1

if |dx| > |dy| then step = |dx| else step = |dy| Now very simple to say that step is the total number of pixels required for a line.

Next step is to find xIncrement and yIncrement: xIncrement = dx/step yIncrement = dy/step

Next a loop is required that will run ‘step’ times. In the loop drawPixel and add xIncrement to x1 and yIncrement to y1. Now sum-up all above in the algorithm:

DDA_Line (Point p1, Point p2) dx = p2.x – p1. x dy = p2.y – p1. y x1=p1.x y1=p1.y if |dx| > |dy| then step = |dx| else step = |dy|

xIncrement = dx/step yIncrement = dy/step for counter = 1 to step drawPixel (x1, y1) x1 = x1 + xIncrement y1 = y1 + yIncrement

Criticism on Algorithm: Use of floating point calculation An algorithm based on integer type calculations is likely to be more efficient

Therefore, after some effort, finally we came up with an algorithm called “Bresenham Line Drawing Algorithm” which would be discussed next.

Bresenham Algorithm Bresenham's algorithm finds the closest integer coordinates to the actual line, using only integer math. Assuming that the slope is positive and less than 1, moving 1 step in the x direction, y either stays the same, or increases by 1. A decision function is required to resolve this choice.

d 1 =y – y i =m * (x i +1)+b – y i d 2 =y i + 1 – y =y i + 1 – m ( x i + 1 ) – b

p i = dx (d 1 -d 2 ) p i = dx (2m * (x i +1) + 2b – 2y i –1 ) p i = 2dy (x i +1) – 2dx y i + dx (2b–1 ) (i) p i = 2 dy x i – 2 dx y i + k (ii) where k = 2 dy + dx (2b-1)

Then we can calculate pi+1 in terms of pi without any x i, y i or k. p i+1 =2 dy x i+1 – 2 dx y i+1 + k p i+1 =2 dy (x i + 1) – 2 dx y i+1 + ksince x i+1 = x i + 1 p i+1 =2 dy x i + 2 dy- 2 dx y i+1 + k (iii)

Now subtracting (ii) from (iii), we get p i+1 – p i =2 dy – 2 dx (y i+1 – y i ) p i+1 =p i + 2 dy – 2 dx (y i+1 – y i )

If the next point is: (x i +1,y i ) then d 1 d 1 – d 2 <0 =>p i <0 =>p i +1 = p i + 2 dy

If the next point is: (x i +1,y i +1) then d 1 >d 2 =>d 1 – d 2 >0 =>p i >0 =>p i +1= p i + 2 dy – 2 dx

The p i is our decision variable, and calculated using integer arithmetic from pre-computed constants and its previous value. Now a question is remaining; i.e. how to calculate initial value of p i ? For that, we use equation (i) and put values (x 1, y 1 )

p i = 2 dy (x 1 +1) – 2 dx y 1 + dx (2b – 1) where b = y – m ximplies that p i = 2 dy x 1 +2 dy – 2 dx y 1 + dx ( 2 (y 1 – mx 1 ) – 1) p i =2 dy x dy – 2 dx y dx y 1 – 2 dy x 1 – dx

there are certain figures that will cancel each other (shown in pairs of different colour) p i =2 dy - dx

dx = x 2 -x 1 dy = y 2 -y 1 p = 2dy-dx c1 = 2dy c2 = 2(dy-dx) x = x 1 y = y 1 plot (x, y, colour)

while (x < x 2 ) x++ if (p < 0) p = p + c 1 else p = p + c 2 y++ plot (x,y,colour)

Improving Performance The use of separate x and y coordinates can be discarded in favour of direct frame buffer addressing. Most algorithms can be adapted to calculate only the initial frame buffer address corresponding to the starting point and to replace: x++ with Addr++ y++ with Addr+=XResolution

Fixed point representation allows a method for performing calculations using only integer arithmetic, but still obtaining the accuracy of floating point values. In fixed point, the fraction part of a value is stored separately, in another integer: M=Mint.Mfrac Mint=Int(M) Mfrac=Frac(M)× MaxInt

Addition in fixed point representation occurs by adding fractional and integer components separately, and only transferring any carry-over from the fractional result to the integer result. The sequence could be implemented using the following two integer additions: ADD Yfrac,Mfrac ; ADC Yint,Mint Improved versions of these algorithms exist. For example the following variations exist on Bresenham's original algorithm:

Symmetry (forward and backward simultaneously) Segmentation (divide into smaller identical segments - GCD(D x,D y) ) Double step, triple step, n step

Setting a Pixel Initial Task: Turning on a pixel (loading the frame buffer/bit- map). Assume the simplest case, i.e., an 8-bit, non- interlaced graphics system. Then each byte in the frame buffer corresponds to a pixel in the output display.

addr(0,0) = the memory address of the initial pixel (0,0) Number of rows = number of raster lines. Number of columns = number of pixels/raster line.

To find the address of a particular pixel (X,Y) we use the following formula: addr(X, Y) = addr(0,0) + Y rows * (Xm + 1) + X (all in bytes) addr(X,Y) = the memory address of pixel (X,Y)

Example: For a system with 640 × 480 pixel resolution, find the address of pixel (X = 340, Y = 150) addr(340, 150) = addr(0,0) * = base + 96,340 is the byte location Graphics systems usually have a command such as set_pixel (x, y) where x, y are integers.

Lets call it a day!

Computer Graphics Lecture 05 Line Drawing Techniques Taqdees A. Siddiqi