Graphics Primitives: line

Slides:



Advertisements
Similar presentations
Line Drawing Algorithms
Advertisements

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.
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
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.
CS 376 Introduction to Computer Graphics 01 / 29 / 2007 Instructor: Michael Eckmann.
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.
Implementation III Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
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.
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.
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
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)
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
CS-321 Dr. Mark L. Hornick 1 Line Drawing Algorithms.
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.
Scan Conversion.
Bresenham’s Line Algorithm
Example: (7,9) (12,0) Example 2: Point1 V:(7,9 ) C:( 0,255,0) Point2 V:(12,0) C:(0,255,0) (0,0) (18,0) (0,9) What are the problems with this method? Slope>1.
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas CS- 375 Graphics and Human Computer Interaction.
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.
Rasterization CENG 477 Introduction to Computer Graphics Slides from Steve Marschner, CS4620, 2008 Cornell University.
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.
Computer Graphics I, Fall 2010 Scan conversion algorithms.
Computer Graphics Lecture 05 Line Drawing Techniques Taqdees A. Siddiqi
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
CSCE 441 Lecture 2: Scan Conversion of Lines
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
University of New Mexico
Implementation III.
Chapter Three Part I Output Primitives CS 380.
Introduction to Computer Graphics with WebGL
CSCE 441 Lecture 2: Scan Conversion of Lines
2D Scan-line Conversion
Rasterization and Antialiasing
Computer Graphics Implementation III
Rasterization and Antialiasing
Edited from The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.
Implementation III Ed Angel Professor Emeritus of Computer Science
Line Drawing Algorithms
Presentation transcript:

Graphics Primitives: line Computer Graphics Graphics Primitives: line

Pixel Position 0 1 2 3 4 5 6 0 1 2 3 4 5 6

Line-Scan Conversion Algorithms Line scan conversion: determine the nearest pixel position (integer) along the line between the two endpoints and store the color for each position in the frame buffer. Three common algorithms DDA Midpoint Bresenham

Line Equations The Cartesian slope-intercept equation ((x0,y0)(xend,yend)) Y=mx+b

Naive Idea Costly floating point computations !! void NaiveLine(int x0,int y0,int xend,int yend,int color)  int x; float y, m, b; m=(yend-y0)/(xend-x0); b = y0 – m*x0; for (x=x0; xxend; x++)  drawpixel (x, int(y+0.5), color); y=m*x+b;  Costly floating point computations !! Multiplications, additions, roundings

DDA (Digital Differential Analyzer) ALGORITHM The digital differential analyzer (DDA) samples the line at unit intervals in one coordinate corresponding integer values nearest the line path of the other coordinate. The following is the basic scan-conversion(DDA) algorithm for line drawing (sample at unit x intervals ) for x from x0 to xend Compute y=mx+b Draw_fn(x, round(y)) How to improve???

Reuse Previous Value Increment For Start from x=x0 and y=y0, every position (x,y) can be computed by incrementation, x by 1 and y by m. Mxi+mdx+b=mxi+b+ mdx= yi +mdx, untuk oktan 1 ketika garis agak landai lompatan lebih rapat adalah x

No more multiplications, but still have fp void DDALine(int x0,int y0,int xend,int yend,int color)  int x; float dx, dy, y, m; dx = xend-x0, dy=yend-y0; m=dy/dx; y=y0; for (x=x0; xxend; x++)  drawpixel (x, int(y+0.5), color); y=y+m;  No more multiplications, but still have fp additions, roundings

Example:draw segment x y int(y+0.5) 0 0 0 1 0+0.4 0 2 0.4+0.4 1 3 0.8+0.4 1 4 1.2+0.4 2 5 1.6+0.4 2 round

DDA Illustration (xi+1, Round(yj+m)) (xi, yj) (xi+1, yj+m) Desired Line (xi+1, Round(yj+m)) (xi, yj) (xi+1, yj+m) (xi, Round(yj)) y2 y1 x1 x2

How about the other cases? The above DDALine only suit the condition that xend>x0 and 0 < m < 1 (octant #1) How about the other cases? |m| > 1 xend < x0?

Octant#2: xend>x0 and 1 < m < ∞ #3 #1 #4 m=0 #5 #8 #6 #7

Octant#2 and #3: reverse the role of x as iterator by y and increment x by 1/m Octant#4: reverse the end points  octant#8 Octant#5: reverse the end points  octant#1 Octant#6: reverse the end points  octant#2 Octant#7: reverse the end points  octant#3 Octant#8: Just same DDA algorithm for octant#1

Has rounding operations the accumulation of error Major deficiency in the above approach : Uses floats Has rounding operations the accumulation of error

According the position of M and Q, choose the next point Pt or Pb Midpoint Algorithm Basic thought( 0 < m < 1) M PT PB P=(x,y) Q Pi(xi,yi) M(xi+1,yi+0.5) According the position of M and Q, choose the next point Pt or Pb

Line equation ( (x0,y0) , (xend,yend) ) Dari y=mx+k terus persamaan y-mx-k=f(x,y) di bawah negatif, di atas positif For any point (x, y): F(x,y) = 0  (x,y) is on the line F(x,y) > 0  (x,y) is above the line F(x,y) < 0  (x,y) is beneath the line

Discriminant Function d The function is made by using the midpoint M: d < 0, M is beneath Q, P2 is next point; d > 0, M is above Q, P1 is the next point; d = 0, P1 or P2 is right, commonly P1 P2 Q P=(x,y) M Pi(xi,yi) P1

Is it (computing the d) costly. No Is it (computing the d) costly? No! We can use the idea in the DDA: use previous d value to compute next one.

Incrementation thought If d0,then choose the next point: P1 (xp+1, yp), In order to judge the next point successively,calculate increment of d is a If d<0,then choose the next point:P2 (xp+1, yp+1)。In order to judge the next point successively ,calculate increment of d is a+b

Initial value of d In each of iteration If d >= 0 Else if d < 0

Improve again: integer calculations?

Substitute 2d for d Initial value of d In each of iteration Implementation issue: the quantities (2a) and (2a+2b) can be precomputed to be two constants. If d >= 0 Else if d<0

Example Drawing a line from (0,0) to (5.2) i xi yi d 1 0 0 1 2 1 0 -3 3 2 1 3 4 3 1 -1 5 4 2 5

void MidpointLine (int x0,int y0,int xend, int yend,int color) { int a, b, incre_d1, incre_d2, d, x, y; a=y0-yend, b=xend-x0, d=2*a+b; incre_d1=2*a, incre_d2=2* (a+b); x=x0, y=y0; drawpixel(x, y, color); while (x<x1) { if (d<0) {x++, y++, d+=incre_d2; } else {x++, d+=incre_d1;} drawpixel (x, y, color); } /* while */ } /* mid PointLine */