8
Bresenham Line Drawing Algorithm බබබබබබබබබබබ බබ බබබ බබබබ බබබබබබබබ බබබබ බබ බබබබබබබබබබ

Bresenham Line Drawing Algorithm

Embed Size (px)

DESCRIPTION

The Bresenham algorithm is another incremental scan conversion algorithm. It is useful alternative for the DDA The big advantage of this algorithm is that it uses only integer calculations

Citation preview

Page 1: Bresenham Line Drawing Algorithm

Bresenham Line Drawing Algorithm

බ්‍රි�සන්හෙ�ම් හෙ� සරල හෙ�ඛා නි�මා ණය සඳ� වූ

ඇල්හෙ� රිතමාය

Page 2: Bresenham Line Drawing Algorithm

The Bresenham algorithm is another incremental scan conversion algorithm. It is useful alternative for the DDAThe big advantage of this algorithm is that it uses only integer calculations

Let’s take following example If starting point is (2,2)and ending point of line is (7,4) calculate the first 3 points of the line by using Bresenham algorithm

Page 3: Bresenham Line Drawing Algorithm

First of all we take first plot of the above line as (2,2) Then we need to calculate constant of followingΔx => 7-2=5Δy => 4-2=22Δy => 42Δx =>102Δy – Δx => 4-5=-12Δy -2Δx=> 4-10=-6

Page 4: Bresenham Line Drawing Algorithm

Then we need to find p1 for plot the second plot of the line

P1= 2Δy – Δx P1= 4-5=-1P1<0 then we are not increasing y from 1(always x increase from 1)Second plot is (3,2)

Use to find P1

Page 5: Bresenham Line Drawing Algorithm

Then we need to find p2 for plot the second plot of the line

When the P1 is less than 1 we use following algorithm to find the next plotP2= P1 +2Δy P2= -1 + 4=3

In this time P2>0 then we increase y from 1(always x increase from 1)Second plot is (4,3)

If P1<0 we use flowing equation to find P2

Page 6: Bresenham Line Drawing Algorithm

Then we need to find p3 for plot the third plot of the line

When the P2 >0 we use following algorithm to find the next plotP3= P2 +2Δy - 2ΔxP3= 3+ 4-10=-3In this time P3<0 then we are not increasing y from 1(always x increase from 1)Third plot is (5,3)

If P2>0 we use flowing equation to find P3

Page 7: Bresenham Line Drawing Algorithm

10 2 3 4 5 6 7

1

2

3

4

5

6

7

Page 8: Bresenham Line Drawing Algorithm

If we take it up to final plots our plots will show as (2,2)(3,2)(4,3)(5,3)(6,4)(7,4)