Unit 1 Notes
Unit 1 Notes
• Presentation Graphics
• Computer Art
• Entertainment
• Visualization
• Image Processing
• 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
• region filling
• clipping
• 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.
The line is defined by two Endpoints. Its density should be separate from
the length of the line.
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 points generation using DDA Algorithm involves the following steps-
Step-01:
Step-02:
• Find the number of steps or points in between the starting and ending
coordinates.
• else
• 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.
Problem-01:
Calculate the points between the starting point (5, 6) and ending point (8, 12).
Solution-
• Given-
Step-01:
• ΔX = Xn – X0 = 8 – 5 = 3
• ΔY =Yn – Y0 = 12 – 6 = 6
• M = ΔY / ΔX = 6 / 3 = 2
Step-02:
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:
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.
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:
• 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.
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-
ΔX = Xn – X0 = 14 – 9 = 5
ΔY =Yn – Y0 = 22 – 18 = 4
Step-02:
Pk
= 2ΔY – ΔX
=2x4–5
Thus,
Xk+1 = Xk + 1 = 9 + 1 = 10
Yk+1 = Yk + 1 = 18 + 1 = 19
(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-
Step-01:
ΔX = Xn – X0 = 30 – 20 = 10
ΔY =Yn – Y0 = 18 – 10 = 8
2.Bresenham Line Drawing Algorithm
Step-02:
= 2ΔY – ΔX
= 2 x 8 – 10= 6
Step-03:
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-
• It is easy to implement.
• The points generated by this algorithm are more accurate than DDA
Algorithm.
• Though it improves the accuracy of generated points but still the resulted line is not smooth.
Given-
The points generation using Mid Point Line Drawing Algorithm involves the
following steps-
Step-01:
ΔX = Xn – X0
3.MidPoint Line Drawing Algorithm
Step-02:
• Dinitial = 2ΔY – ΔX
• ΔD = 2(ΔY – ΔX)
Step-03:
Step-04:
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-
ΔX = Xn – X0 = 30 – 20 = 10
ΔY =Yn – Y0 = 18 – 10 = 8
Step-02:
Dinitial = 2ΔY – ΔX = 2 x 8 – 10 = 6
Step-03:
Thus,
Xk+1 = Xk + 1 = 20 + 1 = 21
Yk+1 = Yk + 1 = 10 + 1 = 11
Calculate the points between the starting coordinates (5, 9) and ending coordinates (12,
16).
Solution-
Given-
Step-01:
ΔX = Xn – X0 = 12 – 5 = 7
ΔY =Yn – Y0 = 16 – 9 = 7
3.MidPoint Line Drawing Algorithm
Step-02:
Dinitial = 2ΔY – ΔX = 2 x 7 – 7 = 7
ΔD = 2(ΔY – ΔX) = 2 x (7 – 7) = 0
Step-03:
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
• It is simple to implement.
• This algorithm may not be an ideal choice for complex graphics and images.
• 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
fc (p, q) < 0
then
If
fc (p, q) = 0
then
If
fc (p, q) > 0
then
• Radius of Circle = R
• The points generation using Mid Point Circle Drawing Algorithm involves
the following steps-
Step-01:
• X0 = 0
• Y0 = R
Midpoint Circle Drawing Algorithm
Step-02:
• 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
Step-05:
• To find the points for other seven octants, follow the eight symmetry
property of circle.
Problem-01:
Given the centre point coordinates (0, 0) and radius as 10, generate all the
points to form a circle.
Solution-
Given-
• Radius of Circle = 10
Midpoint Circle Drawing Algorithm
Step-01:
• X0 = 0
• Y0 = R = 10
Step-02:
• PK = 1 – R
• PK = 1 – 10
• PK = -9
Midpoint Circle Drawing Algorithm
Step-03:
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:
• 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 time-consuming algorithm.
• 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
If fc (x, y) = 0
If fc (x, y) > 0
Given-
• Radius of Circle = R
• X0 = 0
• Y0 = R
Bresenham’s circle drawing algorithm
Step-02:
• 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
Step-05:
• To find the points for other seven octants, follow the eight symmetry
property of circle.
Problem-01:
• Given the centre point coordinates (0, 0) and radius as 8, generate all the points to form a
circle.
Solution-
Given-
• Radius of Circle = 8
Bresenham’s circle drawing algorithm
Step-01:
• X0 = 0
• Y0 = R = 8
Step-02:
• PK = 3 – 2 x R
• PK= 3 – 2 x 8
• PK= -13
Bresenham’s circle drawing algorithm
Step-03:
• Thus,
• Xk+1 = Xk + 1 = 0 + 1 = 1
• Yk+1 = Yk = 8
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
▪ The plotted points are less accurate than the midpoint circle drawing.
Properties of Ellipses
d1 + d2 = constant
• Parametric form
Ellipse Drawing algorithm
Symmetry Considerations
• 4-way symmetry
• Step in x while
Decision parameter:
Initially, we have two decision parameters p1kin region 1 and p2k in region 2.
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).
• Points on the other quadrant will be mirrored from the first quadrant.
• If we draw a tangent at any point on the ellipse at region 1, the slope of the tangent
must be m<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
• dy/dx = -(fx/fy)=(-2xb2/2ya2)
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
Now
Mid-Point Ellipse Algorithm