Graphics Primitives Part II: Bresenhams line and circle.

Slides:



Advertisements
Similar presentations
Contents In today’s lecture we’ll have a look at:
Advertisements

4- 1 Raster Display Model Pixel (Picture Element, 像素 )
Basic Raster Graphics Algorithms for Drawing 2D Primitives
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.
Scan Conversion A. Samal. Scan Conversion Last step in the graphics pipeline Efficiency is a central issue Common primitives – Lines – Polygons – Circles.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Scan conversion of Line , circle & ellipse
30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
Computer Graphics Tz-Huan Huang National Taiwan University (Slides are based on Prof. Chen’s)
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
Lecture 16 Fun with graphics
Raster conversion algorithms for line and circle
Output Primitives Computer Graphics.
Drawing Lines The Bresenham Algorithm for drawing lines and filling polygons.
Graphics Output Primitives Pixel Addressing and Fill Area Dr. M. Al-Mulhem Feb. 1, 2008.
University of Missouri at Columbia 2D Scan-line Conversion University of Missouri at Columbia.
Drawing Lines The Bresenham Algorithm for drawing lines and filling polygons.
Line Drawing by Algorithm. Line Drawing Algorithms Line drawn as pixels Graphics system –Projects the endpoints to their pixel locations in the frame.
Circle Drawing algo..
CGMB214: Introduction to Computer Graphics
Rasterizing primitives: know where to draw the line Dr Nicolas Holzschuch University of Cape Town Modified.
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
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.
College of Computer and Information Science, Northeastern UniversitySeptember 12, CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture.
Dr. S.M. Malaek Assistant: M. Younesi
Jehee Lee Seoul National University
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
Graphics Graphics Korea University cgvr.korea.ac.kr Raster Graphics 고려대학교 컴퓨터 그래픽스 연구실.
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)
Chapter 3 Scan Conversion Lecture-02. Bresenham’s Line Algorithm Bresenham’s line algorithm – is a highly efficient incremental method for scan- converting.
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
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.
Bresenham’s Line Algorithm
Kansas State University Department of Computing and Information Sciences CIS 736: Computer Graphics Friday, January 21, 2000 William H. Hsu Department.
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.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi
Rasterization CENG 477 Introduction to Computer Graphics Slides from Steve Marschner, CS4620, 2008 Cornell University.
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
Scan Conversion or Rasterization
Lecture 9 Line Drawing Algorithms (Bresenham’s Line Algorithm)
Scan Conversion or Rasterization
Prof. Harriet Fell Spring 2007 Lecture 5 – January 17, 2006
Chapter Three Part I Output Primitives CS 380.
Rasterizing Lines 2 Lecture 33 Wed, Nov 14, 2007.
2D Scan-line Conversion
Rasterization and Antialiasing
Line Drawing Algorithms
Rasterization and Antialiasing
Chapter 3 Graphics Output Primitives
Primitive Drawing Algorithm
Primitive Drawing Algorithm
INTERACTIVE COMPUTER GRAPHICS
Presentation transcript:

Graphics Primitives Part II: Bresenhams line and circle

Bresenhams Line Algorithm An accurate, efficient raster line drawing algorithm developed by Bresenham, scan converts lines using only incremental integer calculations that can be adapted to display circles and other curves.

Bresenham Line Algorithm (cont) The difference between these 2 separations is the pixel at (x k,y k ) is to be displayed, the next point will be chosen from (x k +1, y k ) and (x k +1, y K +1) d lower = y – y k = m(x k + 1) + b – y k d upper = (y k + 1) – y = y k + 1- m(x k + 1) – b d lower -d upper = 2m(x k + 1) – 2 y k + 2b – 1

Bresenham s Line Algorithm Define discriminant P k = Δx ( d lower -d upper ) = 2Δyx k -2 Δxy k + c The sign of P k is the same as the sign of d lower -d upper, since Δx > 0. Parameter c is a constant and has the value 2Δy + Δx(2b-1) (independent of pixel position) If p k <0, the next point is (x k +1,y k ); Else the next point is (x k +1,y k +1)

Bresenham s algorithm (cont) Increment thought: At step k + 1, the decision parameter can be evaluated as, p k+1 = 2Δyx k+1 - 2Δxy k+1 + c Taking the difference of p k+ 1 and p k we get the following. p k+1 – p k = 2Δy(x k+1 - x k )-2Δx(y k+1 – y k ) But, x k+1 = x k +1, so that p k+1 = p k + 2Δy - 2 Δx(y k+1 – y k ) Where the term y k+1 -y k is either 0 or 1, depending on the sign of parameter p k If pk<0,p k+1 =p k +2 Δy Else p k+1 =p k +(2Δy -2 Δx)

Bresenham s Line Algorithm Initial value of p 0 The first parameter p 0 is directly computed p 0 = 2 Δyx Δxy 0 + c = 2 Δyx 0 – 2 Δxy 0 + Δx (2b-1) + 2Δy Since (x 0,y 0 ) satisfies the line equation, we also have y 0 = Δy/ Δx * x 0 + b Combining the above 2 equations, we will have p 0 = 2Δy – Δx

Bresenham s Line Algorithm void BresenhamLine (int x 0,int y 0,int x end, int y end,int color) { int dx,dy, incre_p 1, incre_p 2, p, x, y; dy=y end- y 0, dx=x end -x 0 ; incre_p 1 =2*dy, incre_p 2 =2* (dy-dx); x=x 0, y=y 0 ; p=2*dy-dx; drawpixel(x, y, color); while (x<x 1 ) { if (p<0) {x++, p+=incre_d 1 ; } else {x++, y++,p+=incre_d 2 ;} drawpixel (x, y, color); } /* while */ } /* Bresenham */

Circle-Scan conversion algorithm Properties of circle Symmetry X=r cos (theta) Y=r sin (theta) bisa tapi tidak efisien Common algorithms Midpoint Bresenham

Midpoint Circle Algorithm Note that along the circle section from x=0 to x=y in the first octant, the slope of the curve varies from 0 to -1 Circle function around the origin is given by f circle (x,y) = x 2 + y 2 – r 2 Thus, f circle (x,y) < 0 if (x,y) is inside the circle boundary f circle (x,y) = 0 if (x,y) is on the circle boundary f circle (x,y) > 0 if (x,y) is outside the circle boundary

Midpoint Circle Algorithm Define discriminant If d k < 0, the next point is p1; else,the next point is p2

Midpoint Circle Algorithm Improve-Increment thought: If d k <0, choose P 1 (x k +1,y k ) as next point. In order to judge the next point successively calculate Else,choose P 2 (x k +1,y k -1) as next point. In order to judge the next point successively calculate

Midpoint circle algorithm Initial decision parameter is obtained by evaluating the circle function at the start position (x0,y0) = (0,r) d 0 = f circle (1, r-0.5) = 1+ (r-0.5) 2 -r 2 OR

MidPointCircle(int r int color) {int x,y; float d; x=0; y=r; d=1.25-r; circlepoints (x,y,color); //draw (x,y) and other symmetric points while(x<=y) {if(d<0) d+=2*x+3; else { d+=2*(x-y)+5; y--;} x++; circlepoints (x,y,color); }

Improve -Integer calculations Substitute e=d-0.25 for d Untuk e bilangan bulat, jika e negatif d pasti negatif, begitupun sebaliknya

MidPointCircle(int r int color) {int x,y; float d; x=0; y=r; d=1-r; circlepoints (x,y,color); //draw (x,y) and other symmetric points while(x<=y) {if(d<0) d+=2*x+3; else { d+=2*(x-y)+5; y--;} x++; circlepoints (x,y,color); }

Assignment: write and describe midpoint algorithm for ellipse

Ellipse-Scan Conversion algorithm Ellipse equation Symmetry Common algorithms Midpoint Bresenham

Midpoint Ellipse algorithm Ellipse function (x c,y c )=(0,0)

Consider first quadrant because of symmetry A Dividing line Region 1 : unit steps at x direction Region 2: unit steps at y direction