You are on page 1of 41

LINE GENERATION

ALGORITHM
Scan Converting a Straight Line
A straight line may be defined by two endpoints & an
equation.
In fig the two endpoints are described by (x1,y1) and
(x2,y2).
The equation of the line is used to determine the x, y
coordinates of all the points that lie between these two
endpoints.
Scan Converting a Straight Line

Using the equation of a straight line, y = mx + b .


where m =    & b = the y interrupt, we can find values
of y by incrementing x from x =x1, to x = x2.
By scan-converting these calculated x, y values, we
represent the line as a sequence of pixels.
Properties of Good Line Drawing Algorithm
1. Line should appear Straight.

2. Lines should terminate accurately.


Properties of Good Line Drawing Algorithm
3. Lines should have constant density.

4. Line density should be independent of line


length and angle.

5. Line should be drawn rapidly.


Algorithm for line Drawing
 Direct use of line equation

 DDA (Digital Differential Analyzer)

 Bresenham's Algorithm
:Direct use of line equation

It is the simplest form of conversion. 


First of all scan P1 and P2 points. P1 has co-ordinates
(x1',y1') and (x2' y2' ).
Then       m = (y2',y1')/( x2',x1') and b
If value of dx≤0 ,then x=x2 , y=y2 , xend=x1

If value of dx>0, then x=x1 , y=y1 , xend=x2


:Direct use of line equation

Example: A line with starting point as (0, 0) and


ending point (6, 18) is given. Calculate value of
intermediate points and slope of line.
Solution: P1 (0,0) P7 (6,18)
            x1=0
              y1=0
              x2=6
              y2=18
:Direct use of line equation
We know equation of line is
              y =m x + b
              y = 3x + b..............equation (1)
put value of x from initial point in equation (1), i.e., (0, 0) x =0, y=0
       0=3x0+b
              0 = b ⟹ b=0
put b = 0 in equation (1)
              y = 3x + 0
              y = 3x
Now calculate intermediate points
    Let x = 1 ⟹ y = 3 x 1 ⟹ y = 3
    Let x = 2 ⟹ y = 3 x 2 ⟹ y = 6
    Let x = 3 ⟹ y = 3 x 3 ⟹ y = 9
    Let x = 4 ⟹ y = 3 x 4 ⟹ y = 12
    Let x = 5 ⟹ y = 3 x 5 ⟹ y = 15
    Let x = 6 ⟹ y = 3 x 6 ⟹ y = 18
So points are P1 (0,0)
              P2 (1,3)
              P3 (2,6)
              P4 (3,9)
              P5 (4,12)
              P6 (5,15)
              P7 (6,18)
:Algorithm for drawing line using equation
Example: A line with starting point as (1, 2) and
ending point (5, 3) is given. Calculate value of
intermediate points and slope of line.
M=0.25 , b=1.75

X=2 : y=0.25*2+1.75=2.25 (2,2.25)


X=3 : y= 0.25*3+1.75=2.5 (3,2.5)
X=4 : y =0.25*4+1.75=2.75 (4,2.75)
X=5 : y=0.25*5+1.75=3 (5,3)
Digital Differential Analyzer
It's scan conversion of line for drawing line.
DDA Algorithm

Incremental approach.
Difference in pixel is to be analyzed
:Advantage
1. It is a faster method than method of using direct use
of line equation.
2. This method does not use multiplication theorem.
3. It allows us to detect the change in the value of x and
y ,so plotting of same point twice is not possible.
4. This method gives overflow indication when a point
is repositioned.
5. It is an easy method because each step involves just
two additions.
:Disadvantage
1. It involves floating point additions rounding off is
done. Accumulations of round off error cause
accumulation of error.
2. Rounding off operations and floating point
operations consumes a lot of time.
3. It is more suitable for generating line using the
software. But it is less suited for hardware
implementation.
DDA Examples
Example: Draw the line between (5,5) and (10,9)
using DDA algorithm
DDA Examples
Example: Draw the line between (10,8) and (0,0)
using DDA algorithm
It is an efficient
Bresenham's method because it involves only integer
Line Algorithm
addition, subtractions, and multiplication operations.
It can be performed very rapidly so lines can be generated
quickly.
Advantage:
1. It involves only integer arithmetic, so it is simple.
2. It avoids the generation of duplicate points.
3. It can be implemented using hardware.
4.  It is faster as compared to DDA (Digital Differential
Analyzer) because it does not involve floating point
calculations like DDA Algorithm.
M<1
Bresenham's Line Algorithm
M>1
Bresenham's Line Algorithm
Bresenham's Line Algorithm
Example: Consider the line from (1,1) to (8,5)
,Rasterize the line with Bresenham algorithm
Bresenham's Line Algorithm
Example: Draw the line between (20,10) and (30,18)
using Bresenham's Line Algorithm
Bresenham's Line Algorithm
Example: Consider the line from (0,0) to (5,5)
,Rasterize the line with Bresenham algorithm
Circle Drawing Algorithm- Basic Concept of Circle And Its
Representation
Circle Drawing Algorithm
Circle : a set of all points in a plane, which at a fixed
distance from a fixed point.
Drawing a circle on the screen is a little complex than
drawing a line. There are two popular algorithms for
generating a circle :
1. Bresenham’s Algorithm .
2. Midpoint Circle Algorithm.
These algorithms are based on the idea of determining
the subsequent points required to draw the circle.
Circle Drawing Algorithm
Circle is an eight-way symmetric figure.
The shape of circle is the same in all quadrants. In
each quadrant, there are two octants.
If the calculation of the point of one octant is done,
then the other seven points can be calculated easily by
using the concept of eight-way symmetry.
Circle Drawing Algorithm
For drawing, circle considers it at the origin. If a point is P1(x, y), then
the other seven points will be

So we will calculate only 45°arc. From which the whole circle can be
determined easily.
Circle Drawing Algorithm
Example: Let we determine a point (2, 7) of the circle
then other points will be
(2, -7), (-2, -7), (-2, 7), (7, 2), (-7, 2), (-7, -2), (7, -2).
Midpoint Circle Drawing Algorithm
Midpoint Circle Drawing
Example: Draw a circle with radius 5 with centre (2,2)
by using Midpoint Circle Drawing Algorithm
Midpoint Circle Drawing
Midpoint Circle Drawing
Midpoint Circle Drawing
Example: Draw a circle with radius 8 by using
Midpoint Circle Drawing Algorithm
Midpoint Circle Drawing
. Bresenham’s Algorithm
. Bresenham’s Algorithm

Example: Plot 6 points of circle using Bresenham


Algorithm. When radius of circle is 10 units. The circle
has centre (50, 50).
Take initial point (0, 10)
                d = 3 - 2r
                d = 3 - 2 * 10 = -17
                d < 0 ∴ d = d + 4x + 6
                      = -17 + 4 (0) + 6
                      = -11
 symmetry property
 Add the centre values (50,50)
. Bresenham’s Algorithm
Example: Plot points of circle using Bresenham
Algorithm. When radius of circle is 8 units.

You might also like