19
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

Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

  • View
    219

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

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

Page 2: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

Pixel addressing in raster graphics

Pixeladdress

Pixel

x x+1 x+2 x+3 x+4

y

y+1

y+2

y+3

Theoretical length

Actual length

Page 3: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

Raster conversion algorithms: requirements

• visual accuracy

• spatial accuracy

• speed

Page 4: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

Line drawing algorithms

imagessymbols &

y = 2x + 5x0 = 100y0 = 50d = 100

thickness = 4

descriptions

Page 5: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

Line – raster representation

Page 6: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

DDA ( Digital Differential Algorithm )

m < 1

Page 7: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

DDA ( Digital Differential Algorithm )

m > 1

Page 8: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

DDA ( Digital Differential Algorithm )

m > 1

Page 9: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

Digital Differential Algorithm

• input line endpoints, (x0,y0) and (xn, yn)• set pixel at position (x0,y0) • calculate slope m• Case |m|≤1: repeat the following steps until (xn, yn) is reached:• yi+1 = yi + y/ x• xi+1 = xi + 1• set pixel at position (xi+1,Round(yi+1))• Case |m|>1: repeat the following steps until (xn, yn) is reached:• xi+1 = xi + x/ y• yi+1 = yi + 1• set pixel at position (Round(xi+1), yi+1)

Page 10: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

Bresenham's line algorithm

d1

d2

x x+1

y

y = m(x+1) + b

y = mx + b

Page 11: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

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 < 0• set the next pixel at position (xi +1, yi )• calculate new pi+1 = pi + 2 y• if pi ≥ 0• set the next pixel at position (xi +1, yi + 1 )• calculate new pi+1 = pi + 2(y - x)

Page 12: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

DDA versus Bresenham’s Algorithm

• DDA works with floating point arithmetic• Rounding to integers necessary

• Bresenham’s algorithm uses integer arithmetic• Constants need to be computed only once

• Bresenham’s algorithm generally faster than DDA

Page 13: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

Circle generating algorithms

• Direct• Polar coordinate based• Bresenham’s

Page 14: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

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

Page 15: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

Polar coordinates

• Polar coordinate equation

x = xc + r cos

y = yc + r sin

• step through values of from 0 to 2π

Page 16: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

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)

(y,x)

(x,-y)

(y,-x)

(-x,y)

(-y,x)

(-y,-x)

(-x,-y)

Page 17: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

Bresenham’s 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

Page 18: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

4. At each position xk, starting at k = 0, perform the following test:

if pk < 0

plot point at (xk +1, yk)

compute new pk+1 = pk + 2xk+1 + 1else

plot point at (xk + 1, yk – 1)

compute new pk+1 = pk + 2xk+1 + 1 – 2yk+1

where xk+1 = xk + 1 and yk+1 = yk - 1

Page 19: Raster conversion algorithms for line and circle Introduction - Pixel addressing - Primitives and attributes Line drawing algorithms - DDA - Bresenham

5. Determine symmetry points in the other seven octants and plot points

6. Repeat steps 4 and 5 until x y