0% found this document useful (0 votes)
12 views100 pages

Unit 1 Notes

The document provides an overview of computer graphics, image processing, and line drawing algorithms including Digital Differential Algorithm (DDA), Bresenham's Line Algorithm, and Midpoint Line Algorithm. It explains the concepts of pixels, primitives, and the mathematical foundations for drawing lines on a computer screen. Additionally, it outlines the advantages and disadvantages of each algorithm along with practice problems for better understanding.

Uploaded by

Sinduja Baskaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views100 pages

Unit 1 Notes

The document provides an overview of computer graphics, image processing, and line drawing algorithms including Digital Differential Algorithm (DDA), Bresenham's Line Algorithm, and Midpoint Line Algorithm. It explains the concepts of pixels, primitives, and the mathematical foundations for drawing lines on a computer screen. Additionally, it outlines the advantages and disadvantages of each algorithm along with practice problems for better understanding.

Uploaded by

Sinduja Baskaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 100

INTRODUCTION

Computer graphics is an art of drawing pictures, lines, charts, etc using


computers with the help of programming. Computer graphics is made up of
number of pixels.

Image processing is a method to perform some operations on an image, in


order to get an enhanced image or to extract some useful information from
it.

Definition of Computer Graphics:

It is the use of computers to create and manipulate pictures on a display


device. It comprises of software techniques to create, store, modify,
represents pictures.
Application of Computer Graphics

• Computer-Aided Design for engineering and architectural systems etc.

• Presentation Graphics

• Computer Art

• Entertainment

• Education and Training

• Visualization

• Image Processing

• Graphical User Interface


Pixel
• Term that comes from the words PEL (picture element).

• A px (pixel) is the smallest portion of an image or display that a


computer is capable of printing or displaying.

• You can get a better understanding of what a pixel is when zooming into
an image as seen in the picture.

https://youtu.be/15aqFQQVBWU
Primitives

• lines

• circles, arcs, ellipses

• region filling

• clipping

• alphanumeric symbols – text

• lines, circles, character generators (bitmaps), fonts

• Want efficiency & speed (often drawing many primitives)


Scan Converting Lines
• Assume that the line will be 1 pixel thick and will approximate an
infinitely fine line

• What properties should the line have?


• slopes -1 to 1 = 1 pixel / column
• otherwise 1 pixel / row
• constant brightness (irrespective of length or orientation)
• drawn as rapidly as possible

• Other considerations:
• pen style, line style, end point (rounded?),aliasing
❖Assume (unless specified otherwise) that we will represent pixels as
disjoint circles, centered on grid.

❖Idea is to compute the coordinates of a pixel that lies on or near an ideal,


infinitely thin line imposed on a 2D raster grid.

❖For the algorithms discussed below, assume:


▪Integer coordinates of endpoints
▪Pixel on or off (2 states)
▪Slope |m| ≤ 1
Introduction to Line Drawing Algorithm
Line drawing on the computer means the computer screen is dividing into
two parts rows and columns.

Those rows and columns are also known as Pixels.

In case we have to draw a line on the computer, first of all, we need to


know which pixels should be on.

A line is a part of a straight line that extends in the opposite direction


indefinitely.

The line is defined by two Endpoints. Its density should be separate from
the length of the line.

The formula for a line interception of the slope:

Y = mx + b
Introduction to Line Drawing Algorithm
• In this formula, m is a line of the slope and b is intercept of y in the
line. In positions (x1, y1) and (x2, y2), two endpoints are specified
for the line segment.

• The value of slope m and b can be determined accordingly


• m = y2 – y1 / x2 – x1
• i.e. M = Δy / Δx
EXAMPLE
Line endpoints are (0,0) and (4,12). Plot the result to calculate each
value of y as the x steps of 0 to 4.
Solution:
So we have a formula of equation of line:
Y = mx + b
m = y2 – y1 / x2 – x1
m = 12 – 0 / 4 – 0
m=3
• The y intercept b is then found by linking y1 and x1 to the y = 3 x + b
formula, 0 = 3(0) + b.
• Therefore, b = 0, so the y = 3x line formula.
• The goal is to determine the next x, y location as quickly as possible
by the previous one.
Line Drawing Algorithms
We are going to analyze how this process is achieved.
Some useful definitions General requirements
Rasterization: Straight lines must appear as straight lines.
Process of determining which
pixels provide the best
approximation to a desired line on the
screen.

• They must start and end accurately


Scan Conversion:
•Lines should have constant brightness
Combination of rasterization and
generating the picture in scan line along their length
order. •Lines should drawn rapidly
Line Drawing Algorithms

The lines of this object However, they


appear continuous are
made of pixels
Three line drawing algorithms will be discussed below. They are:
• 1. Digital Differential Algorithm (DDA)

• 2. Midpoint Line Algorithm

• 3. Bresenham’s Line Algorithm


1. Digital Differential Algorithm ( DDA)
An incremental conversion method is a DDA Algorithm and also we called Digital
Differential Algorithm (DDA).

• Starting coordinates = (X0, Y0)

• Ending coordinates = (Xn, Yn)

The points generation using DDA Algorithm involves the following steps-

Step-01:

Calculate ΔX, ΔY and M from the given input.

These parameters are calculated as-


❖ ΔX = Xn – X0
❖ ΔY =Yn – Y0
❖ M = ΔY / ΔX
1. Digital Differential Algorithm ( DDA)

Step-02:

• Find the number of steps or points in between the starting and ending
coordinates.

• if (absolute (ΔX) > absolute (ΔY))

• Steps = absolute (ΔX);

• else

• Steps = absolute (ΔY);


1. Digital Differential Algorithm ( DDA)
Step-03:
• Suppose the current point is (Xp, Yp) and the next point is (Xp+1, Yp+1).
• Find the next point by following the below three cases-
1. Digital Differential Algorithm ( DDA)
Step-04:

• Keep repeating Step-03 until the end point is reached or the number of generated new
points (including the starting and ending points) equals to the steps count.

PRACTICE PROBLEMS BASED ON DDA ALGORITHM-

Problem-01:

Calculate the points between the starting point (5, 6) and ending point (8, 12).

Solution-

• Given-

• Starting coordinates = (X0, Y0) = (5, 6)

• Ending coordinates = (Xn, Yn) = (8, 12)


1. Digital Differential Algorithm ( DDA)

Step-01:

• Calculate ΔX, ΔY and M from the given input.

• ΔX = Xn – X0 = 8 – 5 = 3

• ΔY =Yn – Y0 = 12 – 6 = 6

• M = ΔY / ΔX = 6 / 3 = 2

Step-02:

• Calculate the number of steps.

• As |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6


1. Digital Differential Algorithm ( DDA)
Step-03:

• As M > 1, so case-03 is satisfied.

• Now, Step-03 is executed until Step-04 is satisfied.

Xp Yp Xp+1 Yp+1 Round off (Xp+1, Yp+1)

5 6 5.5 7 (6, 7)
6 8 (6, 8)
6.5 9 (7, 9)
7 10 (7, 10)
7.5 11 (8, 11)
8 12 (8, 12)
1. Digital Differential Algorithm ( DDA)
1. Digital Differential Algorithm ( DDA)
Problem-02:
Calculate the points between the starting point (5, 6) and ending point (13, 10).
Solution-
• Given-
• Starting coordinates = (X0, Y0) = (5, 6)
• Ending coordinates = (Xn, Yn) = (13, 10)
Step-01:
Calculate ΔX, ΔY and M from the given input.
• ΔX = Xn – X0 = 13 – 5 = 8
• ΔY =Yn – Y0 = 10 – 6 = 4
• M = ΔY / ΔX = 4 / 8 = 0.50
Step-02:
Calculate the number of steps.
1. Digital Differential Algorithm ( DDA)
Step-03:

• As M < 1, so case-01 is satisfied.

• Now, Step-03 is executed until Step-04 is satisfied.


Xp Yp Xp+1 Yp+1 Round off (Xp+1, Yp+1)

5 6 6 6.5 (6, 7)
7 7 (7, 7)
8 7.5 (8, 8)
9 8 (9, 8)
10 8.5 (10, 9)
11 9 (11, 9)
12 9.5 (12, 10)
13 10 (13, 10)
1. Digital Differential Algorithm ( DDA)
1. Digital Differential Algorithm ( DDA)
Problem-03:

Calculate the points between the starting point (1, 7) and ending point (11, 17).
1. Digital Differential Algorithm ( DDA)
1. Digital Differential Algorithm ( DDA)
Advantages of DDA Algorithm-

• It is a simple algorithm.

• It is easy to implement.

• It avoids using the multiplication operation which is costly in terms of time


complexity.

Disadvantages of DDA Algorithm-

• There is an extra overhead of using round off( ) function.

• Using round off( ) function increases time complexity of the algorithm.

• Resulted lines are not smooth because of round off( ) function.

• The points generated by this algorithm are not accurate.


2.Bresenham Line Drawing Algorithm
Given the starting and ending coordinates of a line, Bresenham Line
Drawing Algorithm attempts to generate the points between the starting and
ending coordinates.
Given-
• Starting coordinates = (X0, Y0)
• Ending coordinates = (Xn, Yn)
The points generation using Bresenham Line Drawing Algorithm involves the
following steps-

Step-01:
Calculate ΔX and ΔY from the given input.
These parameters are calculated as-
• ΔX = Xn – X0
• ΔY =Yn – Y0
2.Bresenham Line Drawing Algorithm
Step-02:

• Calculate the decision parameter Pk.

• It is calculated as-

• Pk = 2ΔY – ΔX

Step-03:

• Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).

• Find the next point depending on the value of decision parameter Pk.

• Follow the below two cases-


2.Bresenham Line Drawing Algorithm

Step-04:

Keep repeating Step-03 until the end point is reached or number of iterations
equals to (ΔX-1) times.
2.Bresenham Line Drawing Algorithm
PRACTICE PROBLEMS BASED ON BRESENHAM LINE DRAWING
ALGORITHM-

Problem-01:

Calculate the points between the starting coordinates (9, 18) and ending
coordinates (14, 22).

Solution-

Given-

Starting coordinates = (X0, Y0) = (9, 18)

Ending coordinates = (Xn, Yn) = (14, 22)


2.Bresenham Line Drawing Algorithm
Step-01:

Calculate ΔX and ΔY from the given input.

ΔX = Xn – X0 = 14 – 9 = 5

ΔY =Yn – Y0 = 22 – 18 = 4

Step-02:

Calculate the decision parameter.

Pk

= 2ΔY – ΔX

=2x4–5

=3 So, decision parameter Pk = 3


2.Bresenham Line Drawing Algorithm
Step-03:
As Pk >= 0, so case-02 is satisfied.

Thus,

Pk+1 = Pk + 2ΔY – 2ΔX = 3 + (2 x 4) – (2 x 5) = 1

Xk+1 = Xk + 1 = 9 + 1 = 10

Yk+1 = Yk + 1 = 18 + 1 = 19

Similarly, Step-03 is executed until the end point is reached or number of


iterations equals to 4 times.

(Number of iterations = ΔX – 1 = 5 – 1 = 4)
2.Bresenham Line Drawing Algorithm
2.Bresenham Line Drawing Algorithm
2.Bresenham Line Drawing Algorithm
Problem-02:

Calculate the points between the starting coordinates (20, 10) and ending
coordinates (30, 18).

Solution-

Given-

Starting coordinates = (X0, Y0) = (20, 10)

Ending coordinates = (Xn, Yn) = (30, 18)

Step-01:

Calculate ΔX and ΔY from the given input.

ΔX = Xn – X0 = 30 – 20 = 10

ΔY =Yn – Y0 = 18 – 10 = 8
2.Bresenham Line Drawing Algorithm
Step-02:

Calculate the decision parameter. Pk

= 2ΔY – ΔX

= 2 x 8 – 10= 6

So, decision parameter Pk = 6

Step-03:

As Pk >= 0, so case-02 is satisfied. Thus,

Pk+1 = Pk + 2ΔY – 2ΔX = 6 + (2 x 8) – (2 x 10) = 2

Xk+1 = Xk + 1 = 20 + 1 = 21

Yk+1 = Yk + 1 = 10 + 1 = 11
2.Bresenham Line Drawing Algorithm
Similarly, Step-03 is executed until the end point is reached or number of
iterations equals to 9 times.(Number of iterations = ΔX – 1 = 10 – 1 = 9)
2.Bresenham Line Drawing Algorithm
2.Bresenham Line Drawing Algorithm
Advantages of Bresenham Line Drawing Algorithm-

The advantages of Bresenham Line Drawing Algorithm are-

• It is easy to implement.

• It is fast and incremental.

• It executes fast but less faster than DDA Algorithm.

• The points generated by this algorithm are more accurate than DDA
Algorithm.

• It uses fixed points only.


2.Bresenham Line Drawing Algorithm

Disadvantages of Bresenham Line Drawing Algorithm-

• The disadvantages of Bresenham Line Drawing Algorithm are-

• Though it improves the accuracy of generated points but still the resulted line is not smooth.

• This algorithm is for the basic line drawing.

• It can not handle diminishing jaggies.


3.MidPoint Line Drawing Algorithm
Given the starting and ending coordinates of a line, Mid Point Line Drawing
Algorithm attempts to generate the points between the starting and ending
coordinates.

Given-

Starting coordinates = (X0, Y0)

Ending coordinates = (Xn, Yn)

The points generation using Mid Point Line Drawing Algorithm involves the
following steps-

Step-01:

Calculate ΔX and ΔY from the given input.

These parameters are calculated as-

ΔX = Xn – X0
3.MidPoint Line Drawing Algorithm
Step-02:

Calculate the value of initial decision parameter and ΔD.

These parameters are calculated as-

• Dinitial = 2ΔY – ΔX

• ΔD = 2(ΔY – ΔX)

Step-03:

The decision whether to increment X or Y coordinate depends upon the


flowing values of Dinitial.

Follow the below two cases-


3.MidPoint Line Drawing Algorithm

Step-04:

Keep repeating Step-03 until the end point is reached.

For each Dnew value, follow the above cases to find the next coordinates.
3.MidPoint Line Drawing Algorithm
PRACTICE PROBLEMS BASED ON MID POINT LINE DRAWING
ALGORITHM-

Problem-01:

Calculate the points between the starting coordinates (20, 10) and ending
coordinates (30, 18).

Solution-

Given-

Starting coordinates = (X0, Y0) = (20, 10)

Ending coordinates = (Xn, Yn) = (30, 18)


3.MidPoint Line Drawing Algorithm
Step-01:

Calculate ΔX and ΔY from the given input.

ΔX = Xn – X0 = 30 – 20 = 10

ΔY =Yn – Y0 = 18 – 10 = 8

Step-02:

Calculate Dinitial and ΔD as-

Dinitial = 2ΔY – ΔX = 2 x 8 – 10 = 6

ΔD = 2(ΔY – ΔX) = 2 x (8 – 10) = -4


3.MidPoint Line Drawing Algorithm

Step-03:

As Dinitial >= 0, so case-02 is satisfied.

Thus,

Xk+1 = Xk + 1 = 20 + 1 = 21

Yk+1 = Yk + 1 = 10 + 1 = 11

Dnew = Dinitial + ΔD = 6 + (-4) = 2


3.MidPoint Line Drawing Algorithm
Similarly, Step-03 is executed until the end point is reached.
3.MidPoint Line Drawing Algorithm
3.MidPoint Line Drawing Algorithm
Problem-02:

Calculate the points between the starting coordinates (5, 9) and ending coordinates (12,
16).

Solution-

Given-

Starting coordinates = (X0, Y0) = (5, 9)

Ending coordinates = (Xn, Yn) = (12, 16)

Step-01:

Calculate ΔX and ΔY from the given input.

ΔX = Xn – X0 = 12 – 5 = 7

ΔY =Yn – Y0 = 16 – 9 = 7
3.MidPoint Line Drawing Algorithm
Step-02:

Calculate Dinitial and ΔD as-

Dinitial = 2ΔY – ΔX = 2 x 7 – 7 = 7

ΔD = 2(ΔY – ΔX) = 2 x (7 – 7) = 0

Step-03:

As Dinitial >= 0, so case-02 is satisfied.

Thus,

Xk+1 = Xk + 1 = 5 + 1 = 6

Yk+1 = Yk + 1 = 9 + 1 = 10

Dnew = Dinitial + ΔD = 7 + 0 = 7
3.MidPoint Line Drawing Algorithm
Similarly, Step-03 is executed until the end point is reached.
3.MidPoint Line Drawing Algorithm
3.MidPoint Line Drawing Algorithm

Advantages of Mid Point Line Drawing Algorithm-

The advantages of Mid Point Line Drawing Algorithm are-

• Accuracy of finding points is a key feature of this algorithm.

• It is simple to implement.

• It uses basic arithmetic operations.

• It takes less time for computation.

• The resulted line is smooth as compared to other line drawing algorithms.


3.MidPoint Line Drawing Algorithm
Disadvantages of Mid Point Line Drawing Algorithm-

• The disadvantages of Mid Point Line Drawing Algorithm are-

• This algorithm may not be an ideal choice for complex graphics and images.

• In terms of accuracy of finding points, improvement is still needed.

• There is no any remarkable improvement made by this algorithm.


Circle Drawing Algorithm
It is not easy to display a continuous smooth arc on the computer screen as
our computer screen is made of pixels organized in matrix form.

So, to draw a circle on a computer screen we should always choose the


nearest pixels from a printed pixel so as they could form an arc.

There are two algorithm to do this:

• Mid-Point circle drawing algorithm

• Bresenham’s circle drawing algorithm


Midpoint Circle Drawing Algorithm
• The midpoint circle drawing algorithm helps us to calculate the complete
perimeter points of a circle for the first octant.

• We can quickly find and calculate the points of other octants with the help of
the first octant points.

• The remaining points are the mirror reflection of the first octant points

• In this algorithm, we define the unit interval and consider the nearest point
of the circle boundary in each step.

• Let us assume we have a point a (p, q) on the boundary of the circle and
with r radius satisfying the equation fc (p, q) = 0
Midpoint Circle Drawing Algorithm

The equation of the circle is


fc (p, q) = p2 + q2 = r2 …………………………… (1)
Midpoint Circle Drawing Algorithm
If

fc (p, q) < 0

then

The point is inside the circle boundary.

If

fc (p, q) = 0

then

The point is on the circle boundary.

If

fc (p, q) > 0

then

The point is outside the circle boundary.


Midpoint Circle Drawing Algorithm
Given-

• Centre point of Circle = (X0, Y0)

• Radius of Circle = R

• The points generation using Mid Point Circle Drawing Algorithm involves
the following steps-

Step-01:

Assign the starting point coordinates (X0, Y0) as-

• X0 = 0

• Y0 = R
Midpoint Circle Drawing Algorithm

Step-02:

• Calculate the value of initial decision parameter PK as-

• PK = 1 – R

Step-03:

• Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).

• Find the next point of the first octant depending on the value of decision parameter Pk.
Midpoint Circle Drawing Algorithm
Follow the below two cases-
Midpoint Circle Drawing Algorithm
Step-04:

• If the given centre point (X0, Y0) is not (0, 0), then do the following and plot
the point-

• Xplot = Xc + X0

• Yplot = Yc + Y0

• Here, (Xc, Yc) denotes the current value of X and Y coordinates.

Step-05:

• Keep repeating Step-03 and Step-04 until Xplot >= Yplot.


Midpoint Circle Drawing Algorithm
Step-06:

• Step-05 generates all the points for one octant.

• To find the points for other seven octants, follow the eight symmetry
property of circle.

• This is depicted by the following figure-


Midpoint Circle Drawing Algorithm
PRACTICE PROBLEMS BASED ON MID POINT CIRCLE DRAWING
ALGORITHM

Problem-01:

Given the centre point coordinates (0, 0) and radius as 10, generate all the
points to form a circle.

Solution-

Given-

• Centre Coordinates of Circle (X0, Y0) = (0, 0)

• Radius of Circle = 10
Midpoint Circle Drawing Algorithm
Step-01:

• Assign the starting point coordinates (X0, Y0) as-

• X0 = 0

• Y0 = R = 10

Step-02:

• Calculate the value of initial decision parameter PK as-

• PK = 1 – R

• PK = 1 – 10

• PK = -9
Midpoint Circle Drawing Algorithm
Step-03:

As Pinitial < 0, so case-01 is satisfied.

Thus,

• Xk+1 = Xk + 1 = 0 + 1 = 1

• Yk+1 = Yk = 10

• Pk+1 = Pk + 2 x Xk+1 + 1 = -9 + (2 x 1) + 1 = -6

Step-04:

• This step is not applicable here as the given centre point coordinates is (0, 0).
Midpoint Circle Drawing Algorithm
Step-05:

• Step-03 is executed similarly until Xk+1 >= Yk+1 as follows-


Midpoint Circle Drawing Algorithm
• Algorithm calculates all the points of octant-1 and terminates.

• Now, the points of octant-2 are obtained using the mirror effect by swapping
X and Y coordinates.
Midpoint Circle Drawing Algorithm

• Now, the points for rest of the part are generated by following the signs of
other quadrants.

• The other points can also be generated by calculating each octant separately.

• Here, all the points have been generated with respect to quadrant-1-
Midpoint Circle Drawing Algorithm
Midpoint Circle Drawing Algorithm
Advantages of Midpoint circle drawing algorithm

✔ It is a powerful and efficient algorithm.

✔ The midpoint circle drawing algorithm is easy to implement.

✔ It is also an algorithm based on a simple circle equation (x2 + y2 = r2).

✔ This algorithm helps to create curves on a raster display.

Disadvantages of Midpoint circle drawing algorithm

▪ It is a time-consuming algorithm.

▪ Sometimes the points of the circle are not accurate.


Bresenham’s circle drawing algorithm

• Bresenham’s algorithm is also used for circle drawing. It is known as


Bresenhams’s circle drawing algorithm.

• It helps us to draw a circle. The circle generation is more complicated than


drawing a line.

• In this algorithm, we will select the closest pixel position to complete the
arc. We cannot represent the continuous arc in the raster display system.

• The different part of this algorithm is that we only use arithmetic integer.
We can perform the calculation faster than other algorithms.
Bresenham’s circle drawing algorithm
Let us assume we have a point p (x, y) on the boundary of the circle
and with r radius satisfying the equation fc (x, y) = 0
Bresenham’s circle drawing algorithm
As we know the equation of the circle is –

fc (x, y) = x2 + y2 = r2

If fc (x, y) < 0

then The point is inside the circle boundary.

If fc (x, y) = 0

then The point is on the circle boundary.

If fc (x, y) > 0

then The point is outside the circle boundary.


Bresenham’s circle drawing algorithm
Procedure-

Given-

• Centre point of Circle = (X0, Y0)

• Radius of Circle = R

• The points generation using Bresenham Circle Drawing Algorithm involves


the following steps-
Step-01:

• Assign the starting point coordinates (X0, Y0) as-

• X0 = 0

• Y0 = R
Bresenham’s circle drawing algorithm
Step-02:

• Calculate the value of initial decision parameter Pk as-

• PK= 3 – 2 x R

Step-03:

• Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).

• Find the next point of the first octant depending on the value of decision
parameter Pk.
Bresenham’s circle drawing algorithm
Follow the below two cases-
Bresenham’s circle drawing algorithm
Step-04:

• If the given centre point (X0, Y0) is not (0, 0), then do the following and plot
the point-

• Xplot = Xc + X0

• Yplot = Yc + Y0

• Here, (Xc, Yc) denotes the current value of X and Y coordinates.

Step-05:

• Keep repeating Step-03 and Step-04 until Xplot => Yplot.


Bresenham’s circle drawing algorithm
Step-06:

• Step-05 generates all the points for one octant.

• To find the points for other seven octants, follow the eight symmetry
property of circle.

• This is depicted by the following figure-


Bresenham’s circle drawing algorithm
PRACTICE PROBLEMS BASED ON BRESENHAM CIRCLE DRAWING
ALGORITHM

Problem-01:

• Given the centre point coordinates (0, 0) and radius as 8, generate all the points to form a
circle.

Solution-

Given-

• Centre Coordinates of Circle (X0, Y0) = (0, 0)

• Radius of Circle = 8
Bresenham’s circle drawing algorithm
Step-01:

• Assign the starting point coordinates (X0, Y0) as-

• X0 = 0

• Y0 = R = 8

Step-02:

• Calculate the value of initial decision parameter Pk as-

• PK = 3 – 2 x R

• PK= 3 – 2 x 8

• PK= -13
Bresenham’s circle drawing algorithm
Step-03:

As Pinitial < 0, so case-01 is satisfied.

• Thus,

• Xk+1 = Xk + 1 = 0 + 1 = 1

• Yk+1 = Yk = 8

• Pk+1 = Pk + 4 x Xk+1 + 6 = -13 + (4 x 1) + 6 = -3

Step-04:

• This step is not applicable here as the given centre point coordinates is (0, 0).
Bresenham’s circle drawing algorithm
Step-05:
• Step-03 is executed similarly until Xk+1 >= Yk+1 as follows-
Bresenham’s circle drawing algorithm
• Algorithm calculates all the points of octant-1 and terminates.

• Now, the points of octant-2 are obtained using the mirror effect by swapping
X and Y coordinates.
Bresenham’s circle drawing algorithm

• Now, the points for rest of the part are generated by following the signs of
other quadrants.

• The other points can also be generated by calculating each octant separately.

• Here, all the points have been generated with respect to quadrant-1-
Bresenham’s circle drawing algorithm
Bresenham’s circle drawing algorithm

Advantages of Bresenham’s Circle Drawing Algorithm

✔ It is simple and easy to implement.

✔ The algorithm is based on simple equation x2 + y2 = r2.

Disadvantages of Bresenham’s Circle Drawing Algorithm

▪ The plotted points are less accurate than the midpoint circle drawing.

▪ It is not so good for complex images and high graphics images.


Ellipse Drawing algorithm
• An ellipse is an elongated circle. Therefore, elliptical curves can be
generated by modifying circle-drawing procedures to take into account the
different dimensions of an ellipse along the major and minor axes

Properties of Ellipses

An ellipse is defined as the set of points


such that the sum of the distances from
two fixed positions (foci) is the same for
all points.

Ellipse generated about foci F1, and F2.


Ellipse Drawing algorithm
• If the distances to the two foci from any point P = (x, y) on the ellipse are
labeled dl and d2, then the general equation of an ellipse can be stated as

d1 + d2 = constant

• Expressing distances d1 and d2 in terms of the focal coordinates F1= (x1,


y1) and F2 = (x2, y2), we have
Ellipse Drawing algorithm
• Equation simplified if ellipse axis parallel to coordinate axis

• Parametric form
Ellipse Drawing algorithm
Symmetry Considerations

• 4-way symmetry

• Unit steps in x until reach region boundary

• Switch to unit steps in y

• Step in x while

• Switch to steps in y when


Mid-Point Ellipse Algorithm

•Midpoint ellipse algorithm plots(finds) points of an ellipse on the first


quadrant by dividing the quadrant into two regions.
•Each point(x, y) is then projected into other three quadrants (-x, y), (x, -y),
(-x, -y) i.e. it uses 4-way symmetry.
Mid-Point Ellipse Algorithm
Function of ellipse:
fellipse(x, y)=x2b2+y2a2 -a2b2

fellipse(x, y)<0 then (x, y) is inside the ellipse.

fellipse(x, y)>0 then (x, y) is outside the ellipse.

fellipse(x, y)=0 then (x, y) is on the ellipse.

Decision parameter:

Initially, we have two decision parameters p1kin region 1 and p2k in region 2.

These parameters are defined as : p1k in region 1 is given as

p1k=ry2+1/4rx2-rx2ry
Mid-Point Ellipse Algorithm
• In this algorithm the ellipse will be drawn. The center of the ellipse will be (0,0).

• To draw an ellipse, we solve the algorithm for the first quadrant.

• Points on the other quadrant will be mirrored from the first quadrant.

• The first quadrant has two regions.

• If we draw a tangent at any point on the ellipse at region 1, the slope of the tangent
must be m<1.

• In the diagram the red tangent with slope <1

• Similarly, if we draw a tangent on the ellipse at any point of region 2, the slope of
the tangent must be greater than one (m>1). In the diagram blue tangent has a
slope >1
Mid-Point Ellipse Algorithm

nd
2 Quadrant 1st Quadrant
Region 1

b Region 2

3rd Quadrant 4th Quadrant


Mid-Point Ellipse Algorithm
• The green tangent is separating each region. The slope of this tangent is
m=-1

• The equation of the ellipse is (x2/a2)+(y2/b2)=1 or x2b2+y2a2 -a2b2 =0=f(x,y)

• We know the slope of the line is m=dy/dx

• The partial derivative of f(x,y) w.r.t.x=fx=2xb2

• The partial derivative of f(x,y) w.r.t.y=fy=2ya2

• dy/dx = -(fx/fy)=(-2xb2/2ya2)

• So when 2xb2>=2ya2 calculation of region 1 stopped and calculation of


region 2 starts
Mid-Point Ellipse Algorithm
Region 1

• The slope of the tangent (m<1)

• X value increases at the unit intervals so xk+1= xk +1

• The y value will either yk or yk-1

• So the next point will be either (xk+1,yk)(xk+1,yk-1)

• The mid point =(xm,ym)


Putting the value of midpoint in the ellipse equation we get the decision
parameter p1k

Now
Mid-Point Ellipse Algorithm

The Ellipse starts from (0,b), therefore putting (0,b) in P1k we get ,
P1k =(0+1)2b2+(b-1/2) 2a2-a2b2
Or
P1k =b2+ b2 a2+1/4a2-a2b- a2b2
or
P1k =b2+1/4a2-a2b[initial decision parameter for first region]
Now, if P1k =>=0 then the next coordinate is (xk+1,yk-1)
Else if P1k <0 then the next coordinate is (xk+1,yk)
Mid-Point Ellipse Algorithm
Region 2

• The slope of the tangent (m>1)

• y value decreases at the unit intervals so yk+1= yk -1

• The x value will either xk or xk+1

• So the next point will be either (xk,yk -1) or (xk+1,yk-1)

• The mid point =(xm,ym)


Mid-Point Ellipse Algorithm
Putting the value of midpoint in the ellipse equation we get the decision
parameter P2k

Now
Mid-Point Ellipse Algorithm

The initial decision parameter value will be calculated after completing


the first region
Now, if P2k >0 then the next coordinate is (xk,yk-1)
Else if P2k <0 the the next coordinate is is (xk+1,yk-1)

You might also like