Raster conversion algorithms for line and circle - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Raster conversion algorithms for line and circle

Description:

Raster conversion algorithms for line and circle. Introduction - Pixel addressing ... Line raster representation. DDA ( Digital Differential Algorithm ) m 1 ... – PowerPoint PPT presentation

Number of Views:211
Avg rating:3.0/5.0
Slides: 20
Provided by: ela50
Category:

less

Transcript and Presenter's Notes

Title: Raster conversion algorithms for line and circle


1
Raster conversion algorithms for line and circle
  • Introduction
  • - Pixel addressing
  • - Primitives and attributes
  • Line drawing algorithms
  • - DDA
  • - Bresenham
  • Circle generating algorithms
  • - Direct method
  • - Bresenham algorithm

2
Pixel addressing in raster graphics
3
Raster conversion algorithms requirements
  • visual accuracy
  • spatial accuracy
  • speed

4
Line drawing algorithms
5
Line raster representation
6
DDA ( Digital Differential Algorithm )
m lt 1
7
DDA ( Digital Differential Algorithm )
m gt 1
8
DDA ( Digital Differential Algorithm )
m gt 1
9
Digital Differential Algorithm
  • input line endpoints, (x0,y0) and (xn, yn)
  • set pixel at position (x0,y0)
  • calculate slope m
  • Case m1 repeat the following steps until (xn,
    yn) is reached
  • yi1 yi ?y/ ?x
  • xi1 xi 1
  • set pixel at position
    (xi1,Round(yi1))
  • Case mgt1 repeat the following steps until (xn,
    yn) is reached
  • xi1 xi ?x/ ?y
  • yi1 yi 1
  • set pixel at position
    (Round(xi1), yi1)

10
Bresenham's line algorithm
y mx b
y mx b
y
x
x1
11
Bresenham's line algorithm (slope 1)
  • input line endpoints, (x0,y0) and (xn, yn)
  • calculate ?x xn - x0 and ?y yn - y0
  • calculate parameter p0 2 ?y - ?x
  • set pixel at position (x0,y0)
  • repeat the following steps until (xn, yn) is
    reached
  • if pi lt 0
  • set the next pixel at position (xi 1, yi )
  • calculate new pi1 pi 2 ?y
  • if pi 0
  • set the next pixel at position (xi 1, yi 1 )
  • calculate new pi1 pi 2(?y - ?x)

12
DDA versus Bresenhams Algorithm
  • DDA works with floating point arithmetic
  • Rounding to integers necessary
  • Bresenhams algorithm uses integer arithmetic
  • Constants need to be computed only once
  • Bresenhams algorithm generally faster than DDA

13
Circle generating algorithms
  • Direct
  • Polar coordinate based
  • Bresenhams

14
Direct circle algorithm
  • Cartesian coordinates
  • Circle equation
  • ( x - xc )2 ( y - yc )2 r2
  • Step along x axis from xc - r to xc r and
    calculate
  • y yc ? r2 - ( x - xc )2

15
Polar coordinates
  • Polar coordinate equation
  • x xc r cos?
  • y yc r sin?
  • step through values of ? from 0 to 2p

16
Optimisation and speed-up
  • Symmetry of a circle can be used
  • Calculations of point coordinates only for a
    first one-eighth of a circle

(x,y)
(-x,y)
(y,x)
(-y,x)
(-y,-x)
(y,-x)
(x,-y)
(-x,-y)
17
Bresenhams circle algorithm
  • 1. Input radius r
  • 2. Plot a point at (0, r)
  • 3. Calculate the initial value of the decision
    parameter as p0 5/4 r 1 r

18
  • 4. At each position xk, starting at k 0,
    perform the following test
  • if pk lt 0
  • plot point at (xk 1, yk)
  • compute new pk1 pk 2xk1 1
  • else
  • plot point at (xk 1, yk 1)
  • compute new pk1 pk 2xk1 1 2yk1
  • where xk1 xk 1 and yk1 yk - 1

19
  • 5. Determine symmetry points in the other seven
    octants and plot points
  • 6. Repeat steps 4 and 5 until x ? y
Write a Comment
User Comments (0)
About PowerShow.com