Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.

Slides:



Advertisements
Similar presentations
Circle Drawing Asst. Prof. Dr. Ahmet Sayar Kocaeli University
Advertisements

Contents In today’s lecture we’ll have a look at:
Graphics Primitives Part II: Bresenhams line and circle.
Graphics Primitives: line
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.
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.
30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
In the name of God Computer Graphics Bastanfard.
Raster conversion algorithms for line and circle
Output Primitives Computer Graphics.
Graphics Output Primitives Pixel Addressing and Fill Area Dr. M. Al-Mulhem Feb. 1, 2008.
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..
March Shape Drawing Algorithms Shmuel Wimer Bar Ilan Univ., Engineering Faculty.
CGMB214: Introduction to Computer Graphics
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
1 CS 430/536 Computer Graphics I Circle Drawing and Clipping Week 3, Lecture 6 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent.
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
1 Circle Drawing Algorithms Pictures snagged from
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)
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
MIDPOINT CIRCLE & ELLIPSE GENERARTING 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.
Midpoint Circle Algorithm
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.
Scan Conversion.
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.
Instructor: Dr. Shereen Aly Taie If (P>0)
Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing
Write Bresenham’s algorithm for generation of line also indicate which raster locations would be chosen by Bresenham’s algorithm when scan converting.
Chun-Yuan Lin Coordinate Reference Frames 2016/6/22 1 CG.
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
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.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
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
Raster Graphics.
MID-POINT CIRCLE ALGORITHM
Lecture 9 Line Drawing Algorithms (Bresenham’s Line Algorithm)
Coordinate Reference Frames
Scan Conversion or Rasterization
Lecture 05: Mid-point Ellipse algorithm Dr. Manal Helal – Fall 2014
Chapter Three Part I Output Primitives CS 380.
CSCE 441 Lecture 2: Scan Conversion of Lines
Scan Conversion of Circles
Scan Conversion (From geometry to pixels)
Chapter 3 Graphics Output Primitives
Presentation transcript:

Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014

Output primitives Graphics programming packages provide functions to describe a scene in terms of basic geometric structures referred to as Output Primitives Output primitives include: –Points –Lines –Circles –Spline curves

Output primitives can be used to present more complex objects

A point is plotted by setting the bit value corresponding to a specified screen position within the frame buffer to 1 In RGB system, the frame buffer is loaded with the color codes for intensities to be displayed

Line drawing: –Is accomplished by calculating intermediate positions along the line path between two specified endpoint positions –Digital devices display a straight line segment by plotting discrete points between the two endpoints

Discrete coordinate positions along the line path are calculated from the equation of the line – Screen locations are referenced with integer values, so plotted positions may only approximate actual Line positions –A computed line position of (10.48,20.51), for example, would be converted to pixel position (10,21) –This rounding of coordinate values to integers causes lines to be displayed with a stair-step appearance

Line Drawing Algorithms The straight line equation –m represents the slope –b as the y intercept Given the end points of a line (x 1, y 1 ) and (x 2, y 2 ), we can determine the values of m and b

For any given x interval Δx along a line, we can compute the corresponding y interval Δy Similarly, we can obtain the x interval Δ x corresponding to a specified Δ y as

These equations form the basis for determining deflection voltages in analog devices –For lines with slope magnitudes ImI < 1, Δx can be set proportional to a small horizontal deflection voltage and the corresponding vertical deflection is then set proportional to Δy using: –For lines whose slopes have magnitudes ImI > 1, Δy can be set proportional to a small vertical deflection voltage with the corresponding horizontal deflection voltage set proportional to Δx using:

–For lines with m = 1, Δx = Δy and the horizontal and vertical deflections voltages are equal On raster systems, lines are plotted with pixels –Step sizes in the horizontal and vertical directions are constrained by pixel separations. –That is, we must "sample" a line at discrete positions and determine the nearest pixel to the line at each sampled position.

Bresenham's Line Algorithm It decides which of two possible pixel positions is closer to the line path at each sample step This is done by testing the sign of an integer parameter, whose value is proportional to the difference between the separations of the two pixel positions from the actual line path. Is using incremental integer calculations

Pixel positions along a line path are determined by sampling at unit x intervals For point (x o, y o ) of a given line, we step to each successive column (x position) and plot the pixel whose y value is closest to the line path. –Assuming we have a pixel at (x k, y k ) is displayed, we next need to decide which pixel to plot in column x k+1 –The choices are the pixels at positions (x k +1, y k ) and (x k +1, y k +1).

We label vertical pixel separations from the mathematical line path as d 1, and d 2 The coordinate on the mathematical line at pixel column position x k +1 is calculated as shown in next slide

Then and

The difference between these two separations is At step k, a decision parameter p k is used The sign of p k is the sine of d 1 -d 2, since Δx > 0 for our example

Then c is independent of pixel position and will be eliminated in the recursive calculations for p k

If the pixel at y k is closer to the line path than the pixel at y k +1 (i.e. d 1 <d 2 ) then p k is negative so we plot lower pixel; otherwise we plot the upper pixel

At step k+1, the decision parameter will be Then But, x k+1 = x k +1 Where y k+1 -y k is either 0 or 1 depending on the sign of p k

This recursive calculation is done at each x position P 0 is calculated at the starting point (x 0, y 0 ) Since the constants 2Δy and 2Δy- 2Δx are calculated once Then the calculations include only subtraction and addition

Bresenham algorithm for |m|<1 1.Input the two line endpoints and store the left endpoint in (x 0, y 0 ) 2.Load (x 0, y 0 ) into the frame buffer; that is, plot the first point. 3.Calculate constants Δx, Δy, 2Δy, and 2Δy- 2Δx, and obtain the starting value for the decision parameter as

4.At each x k along the line, starting at k = 0, perform the following test: –If P k < 0, the next point to plot is (x k +1,y k )and –Otherwise, the next point to plot is (x k +1, y k +1) and 5.Repeat step 4, Δx times

Example, a line from (20, 10) to (30, 18) – Δx = 10, Δy = 8, then m=0.8 –2Δy = 16, 2Δy-2Δx = 4 –P 0 = 2Δy - Δx = 6 –Plot initial point (20, 10) –Repeat applying one of the following:

MID-POINT CIRCLE ALGORITHM

Circle Generation Algorithm The circle is a frequently used component in pictures and graphs A procedure for generating either full circles or circular arcs is included in most graphics packages.

Properties of Circles A circle is defined as the set of points that are all at a given distance r from a center position (x c, y c ) This distance relationship is expressed by the Pythagorean theorem in Cartesian coordinates as

We could use this equation to calculate the position of points on a circle circumference by stepping along the x axis in unit steps from x c - r to x c + r and calculating the corresponding y values at each position as

This is not the best method for generating a circle for the following reasons: 1.It involves considerable computation at each step 2.The spacing between plotted pixel positions is not uniform

Another way to eliminate the unequal spacing is to calculate points along the circular boundary using polar coordinates r and ɵ

Notes: 1.The step size chosen for ɵ depends on the application and the display device 2.Computation can be reduced by considering the symmetry of circles

3.The Cartesian equation involves multiplications and square root calculations 4.The polar equations contain multiplications and trigonometric calculations. 5.More efficient circle algorithms are based on incremental calculation of decision parameters, as in the Bresenham line algorithm, which involves only simple integer operations

Solution: –To get a direct distance comparison, test the halfway position between two pixels to determine if this midpoint is inside or outside the circle boundary

Midpoint Circle Algorithm Sample at unit intervals and determine the closest pixel position to the specified circle path at each step First step –calculate pixel positions around a circle path centered at the coordinate origin (0,0). –Then each calculated position (x, y) is moved to its proper screen position by adding x c, to x and y c, to y

we can take unit steps in the positive x direction over one octant, then use the symmetry To apply the midpoint method, we define a circle function:

the circle function is the decision parameter in the midpoint algorithm, and we can set up incremental calculations for this function as we did in the line algorithm. Assuming we have just plotted the pixel at (x k, y k ) –we next need to determine whether the pixel at position (x k + 1, y k ) or the one at position (x k + 1, y k - 1) is closer to the circle.

The relative position of any point (x, y) can be determined by checking the sign of the circle function

Our decision parameter is the circle function evaluated at the midpoint between these two pixels: –If p k < 0, this midpoint is inside the circle and the pixel on scan line y k is closer to the circle boundary. –Otherwise, the mid-position is outside or on the circle boundary, and we select the pixel on scan line y k - 1.

We obtain a recursive expression for the next decision parameter by evaluating the circle function at sampling position x k = x k + 2: or

where y k+1 is either y k or y k-1 depending on the sign of p k. increments for obtaining p k+1, are either –2x k (if p k is negative) –or 2x k – 2y k+1

Evaluation of the terms 2x k+1, and 2y k+1, can also be done incrementally as

The initial decision parameter is obtained by evaluating the circle function at the start position (x 0, y 0 ) = (0, r) or If the radius r is specified as an integer, we can simply round p 0 to

Midpoint Circle Algorithm 1.Input radius r and circle center (x c, y c ), and obtain the first point on the circumference of a circle centered on the origin as : (x 0, y 0 ) = (0, r) 2.calculate the initial value of the decision parameter as:

3.At each x k position, starting at k = 0, perform the following test: –If p k < 0, the next point along the circle centered on (0,0) is (x k+1, y k ) and –Otherwise, the next point along the circle is (x k + 1, y k - 1) and –Where

4.Determine symmetry points in the other seven octants. 5.Move each calculated pixel position (x, y) onto the circular path centered on (x c, y c ) and plot the coordinate values: 6.Repeat steps 3 through 5 until x >= y.

Example –Given a circle radius r = 10 –Consider the first quadrant from x = 0 to x = y. –The initial value of the decision parameter is p 0 = 1 - r = -9 –For the circle centered on the coordinate origin, the initial point is (x 0, y 0 ) = (0, 10) –initial increment terms for calculating the decision parameters are 2x 0 = 0, 2y 0 = 20

Successive decision parameter values and positions along the circle path are calculated as: (x k+1, y k ) (x k + 1, y k - 1)