0% found this document useful (0 votes)
9 views

class 2

The document provides an overview of Bresenham's Line Drawing Algorithm and its application in computer graphics, detailing its efficiency in raster line generation using integer calculations. It explains the decision parameter used to determine pixel selection based on line slope and includes a description of the midpoint circle algorithm for drawing circles. Additionally, it covers the properties of circles and the symmetry that can be utilized to optimize computations.
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)
9 views

class 2

The document provides an overview of Bresenham's Line Drawing Algorithm and its application in computer graphics, detailing its efficiency in raster line generation using integer calculations. It explains the decision parameter used to determine pixel selection based on line slope and includes a description of the midpoint circle algorithm for drawing circles. Additionally, it covers the properties of circles and the symmetry that can be utilized to optimize computations.
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/ 73

Computer Graphics

Class 2
Online class for
PSC and NEA
BLA, circle, ellipse
Associate Professor
9801104103
[email protected]

1/28/2025 Associate Professor Sujan Shrestha


Computer Graphics

Bresenham’s Line
Drawing
algorithms
Associate Professor
9801104103
[email protected]

1/28/2025 Associate Professor Sujan Shrestha


Introduction to Bresenham’s Line
Algorithm
• An accurate and efficient raster line-generating
algorithm, developed by Bresenham.
• It scan converts line using only incremental integer
calculations.
• That can be modified to display circles and other
curves.
• Based on slop we take unit step in one direction and
decide pixel of other direction from two candidate
pixel.
• If |Δ𝑥| > |Δ𝑦| we sample at unit 𝒙 interval and vice
versa.
Line Path & Candidate pixel
• Example |ΔX| > |ΔY|, and ΔY is “+ve”. 4
3
Initial point (Xk, Yk) 2
Line path 1
Candidate pixels {(Xk+1, Yk), (Xk+1, Yk+1)} 0
0 1 2 3 4

 Now we need to decide which candidate pixel is more closer to


actual line.
 For that we use decision parameter (Pk) equation.
 Decision parameter can be derived by calculating distance of actual
line from two candidate pixel.
Derivation Bresenham’s Line Algorithm
• 𝑦 = 𝑚𝑥 + 𝑏 [Line Equation] 4
• 𝑦 = 𝑚(𝑥𝑘 ) + 𝑏 [Actual Y value at Xk 3
position] 2
1
• 𝑦 = 𝑚(𝑥𝑘 + 1) + 𝑏 [Actual Y value at Xk 0
+1position]
0 1 2 3 4
Distance between actual line position and lower
candidate pixel
• 𝑑1 = 𝑦 − 𝑦𝑘
• 𝑑1 = 𝑚(𝑥𝑘 + 1) + 𝑏 − 𝑦𝑘
Distance between actual line position and upper
candidate pixel
• 𝑑2 = (𝑦𝑘 +1) − 𝑦
• 𝑑2 = (𝑦𝑘 +1) − 𝑚 𝑥𝑘 + 1 − 𝑏
Contd.
Calculate 𝑑1 − 𝑑2
• 𝑑1 − 𝑑2 = 𝑚 𝑥𝑘 + 1 + 𝑏 − 𝑦𝑘 − (𝑦𝑘 +1 − 𝑚 𝑥𝑘 + 1 − 𝑏}
• 𝑑1 − 𝑑2 = 𝑚𝑥𝑘 + 𝑚 + 𝑏 − 𝑦𝑘 − {𝑦𝑘 + 1 − 𝑚𝑥𝑘 − 𝑚 − 𝑏}
• 𝑑1 − 𝑑2 = 2𝑚 𝑥𝑘 + 1 − 2𝑦𝑘 + 2𝑏 − 1
• 𝑑1 − 𝑑2 = 2(∆𝑦/∆𝑥) 𝑥𝑘 + 1 − 2𝑦𝑘 + 2𝑏 − 1 [Put 𝑚 = Δ𝑦/Δ𝑥]
Decision parameter
• 𝑝𝑘 = ∆𝑥(𝑑1 − 𝑑2 )
• 𝑝𝑘 = ∆𝑥 {2(∆𝑦/∆𝑥) 𝑥𝑘 + 1 − 2𝑦𝑘 + 2𝑏 − 1 }
• 𝑝𝑘 = 2∆𝑦𝑥𝑘 − 2∆𝑥𝑦𝑘 + 2∆𝑦 + 2∆𝑥𝑏 − ∆x
• 𝑝𝑘 = 2∆𝑦𝑥𝑘 − 2∆𝑥𝑦𝑘 + C [Replacing single constant C for simplicity]
Similarly
• 𝑝𝑘+1 = 2∆𝑦𝑥𝑘+1 − 2∆𝑥𝑦𝑘+1 + C
Contd.
Subtract 𝑝𝑘 from 𝑝𝑘+1
• 𝑝𝑘+1 − 𝑝𝑘 = 2∆𝑦𝑥𝑘+1 − 2∆𝑥𝑦𝑘+1 + C − 2∆𝑦𝑥𝑘 + 2∆𝑥𝑦𝑘 − C
• 𝑝𝑘+1 − 𝑝𝑘 = 2∆𝑦(𝑥𝑘+1 −𝑥𝑘 ) − 2∆𝑥(𝑦𝑘+1 −𝑦𝑘 )
[where (𝑥𝑘+1 −𝑥𝑘 ) = 1]
• 𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑦 − 2∆𝑥(𝑦𝑘+1 −𝑦𝑘 )
[where (𝑦𝑘+1 −𝑦𝑘 ) = 0 or 1 depending on selection of previous pixel]

• If 𝑝𝑘 < 0, the next point to plot is (𝑥𝑘 + 1, 𝑦𝑘 ) and


𝑥𝑘+1 = 𝑥𝑘 + 1,
𝑦𝑘+1 = 𝑦𝑘
𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑦

Otherwise, the next point to plot is (𝑥𝑘 + 1, 𝑦𝑘 + 1) and


𝑥𝑘+1 = 𝑥𝑘 + 1,
𝑦𝑘+1 = 𝑦𝑘 + 1
𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑦 − 2∆𝑥
Initial Decision parameter
• The first decision parameter 𝑝0 is calculated using equation of 𝑝𝑘.
• 𝑝𝑘 = 2∆𝑦𝑥𝑘 − 2∆𝑥𝑦𝑘 + 2∆𝑦 + 2∆𝑥𝑏 − ∆x
• 𝑝0 = 2∆𝑦𝑥0 − 2∆𝑥𝑦0 + 2∆𝑦 + 2∆𝑥𝑏 − ∆x [Put 𝑘 = 0]
• 𝑝0 = 2∆𝑦𝑥0 − 2∆𝑥𝑦0 + 2∆𝑦 + 2∆𝑥 𝑦0 − 𝑚𝑥0 − ∆x
[Substitute 𝑏 = 𝑦0 – 𝑚𝑥0]
• 𝑝0 = 2∆𝑦𝑥0 − 2∆𝑥𝑦0 + 2∆𝑦 + 2∆𝑥(𝑦0 − (∆𝑦/∆𝑥)𝑥0 ) − ∆x
[Substitute 𝑚 = ∆𝑦/Δ𝑥]
• 𝑝0 = 2∆𝑦𝑥0 − 2∆𝑥𝑦0 + 2∆𝑦 + 2∆𝑥𝑦0 − 2∆𝑦𝑥0 − ∆x
• 𝑝0 = 2∆𝑦 − ∆x
[Initial decision parameter with all terms are constant]
Bresenham’s Line Algorithm
1. Input the two line endpoints and store the left endpoint in
(𝑥0 , 𝑦0 ).
2. Load (𝑥0 , 𝑦0 ) into the frame buffer; that is, plot the first point.
3. Calculate constants ∆𝑥, ∆𝑦, 2∆𝑦, and 2∆𝑦 − 2∆𝑥, and obtain
the starting value for the decision parameter as
𝑝0 = 2∆𝑦 − ∆𝑥
4. At each 𝑥𝑘 along the line, starting at 𝑘 = 0, perform the
following test:
If 𝑝𝑘 < 0, the next point to plot is (𝑥𝑘 + 1, 𝑦𝑘 ) and
𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑦
Otherwise, the next point to plot is (𝑥𝑘 + 1, 𝑦𝑘 + 1) and
𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑦 − 2∆𝑥
5. Repeat step-4 ∆𝑥 times.
Description of Bresenham’s Line
Algorithm
• Bresenham’s algorithm is generalized to lines with arbitrary slope.
• For lines with positive slope greater than 1 we interchange the
roles of the 𝑥 and 𝑦 directions.
• Also we can revise algorithm to draw line from right endpoint to
left endpoint, both 𝑥 and 𝑦 decrease as we step from right to left.
• When 𝑝𝑘 = 0 we can choose either lower or upper pixel but same
for whole line.
• For the negative slope the procedure are similar except that now
one coordinate decreases as the other increases.
• The special case handle separately by loading directly into the
frame buffer without processing.
 Horizontal line (∆𝑦 = 0),
 Vertical line (∆𝑥 = 0)
 Diagonal line with |∆𝑥| = |∆𝑦|
Example Bresenham’s Line
Algorithm
• Example: Draw line 𝐴𝐵 with coordinates 𝐴(2,2), 𝐵(6,4). 4
• Plot left end point 𝐴(2, 2). 3
• Calculate: 2
• ∆𝑥 = 4, 1
• ∆𝑦 = 2,
• 2∆𝑦 = 4,
0
• 2∆𝑦 − 2∆𝑥 = −4,
0 1 2 3 4 5 6 7 8
• 𝑝0 = 2∆𝑦 − ∆𝑥 = 0
• Now 𝑝0 ≮ 0 so we select upper pixel (3, 3).
• 𝑝1 = 𝑝0 + 2∆𝑦 − 2∆𝑥 = 0 + −4 = −4
• Now 𝑝1 < 0 so we select lower pixel (4, 3).
• 𝑝2 = 𝑝1 + 2∆𝑦 = −4 + 4 = 0
• Now 𝑝2 ≮ 0 so we select upper pixel (5, 4).
• 𝑝3 = 𝑝2 + 2∆𝑦 − 2∆𝑥 = 0 + −4 = −4
• Now 𝑝3 < 0 so we select lower pixel (6, 4).
Computer Graphics

Scan Conversion
continued…

Associate Professor
9801104103
[email protected]

Associate Professor Sujan Shrestha


Circle
• A circle is defined as the set of points that are all at a given distance 𝑟
from a center position say (𝑥𝑐 , 𝑦𝑐 ).

Center
(𝑥𝑐 , 𝑦𝑐 )

r
Radius
Properties of Circle- Cartesion Coordinate
• Cartesian coordinates equation :
• (𝑥 − 𝑥𝑐 )2 +(𝑦 − 𝑦𝑐 )2 = 𝑟 2

For center (0,0)


• 𝑥2 + 𝑦2 = 𝑟2
Properties of Circle- Symmetry
• Computation can be reduced by considering symmetry city property of circles.
• The shape of circle is similar in each octant.
(-3, 4) (3, 4)
(-Y, X) (Y, X)
(-4, 3) (4, 3)
(-X, Y) (X, Y)
45𝑂
(-4, -3) (4, -3)
(-X, -Y) (X, -Y)

(-Y, -X) (Y, -X)


(-3, -4) (3, -4)
Decision Parameter Midpoint Circle Algorithm
• Position in the other seven octants are then obtain by
symmetry.
• For the decision parameter we use the circle function which
is:
𝑓𝑐𝑖𝑟𝑐𝑙𝑒 𝑥, 𝑦 = 𝑥 2 + 𝑦 2 − 𝑟 2
< 0 𝑖𝑓 𝑥, 𝑦 𝑖𝑠 𝑖𝑛𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑐𝑖𝑟𝑐𝑙𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
𝑓𝑐𝑖𝑟𝑐𝑙𝑒 𝑥, 𝑦 = 0 𝑖𝑓 𝑥, 𝑦 𝑖𝑠 𝑜𝑛 𝑡ℎ𝑒 𝑐𝑖𝑟𝑐𝑙𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
> 0 𝑖𝑓 𝑥, 𝑦 𝑖𝑠 𝑜𝑢𝑡𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑐𝑖𝑟𝑐𝑙𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
• Above equation we calculate for the mid positions between
pixels near the circular path at each sampling step.
• And we setup incremental calculation for this function as we
did in the line algorithm.
Mid-point circle drawing algorithm
Let’s start from (0, r), Determine the steps for point, here ∆x = 1,
∆y = -m
xk+1 = xk + 1, yk+1 = yk - 1/2

xk always increments by 1means xk+1 =xk + 1 whereas yk need to


be checked with midpoint and yk+1 can be either yk or yk-1

If (xk, yk) already plotted then,


xk+12 + yk+12 - r2 < 0 , means (xk+1, yk+1) lies inside the circle boundary,
xk+12 + yk+12 - r2 = 0 , means (xk+1, yk+1) lies on the circle boundary, ……….(1)
xk+12 + yk+12 - r2 > 0 , means (xk+1, yk+1) lies outside the circle boundary
Midpoint between Candidate pixel
• Figure shows the midpoint between the two candidate pixels at sampling position
𝑥𝑘 + 1.
𝒙𝟐 + 𝒚𝟐 − 𝒓𝟐 = 𝟎

yk Midpoint

Candidate Pixel
yk+1

xk xk+1 xk+2

• Assuming we have just plotted the pixel at 𝑥𝑘 , 𝑦𝑘 .


• Next we determine whether the pixel at position 𝑥𝑘 + 1, 𝑦𝑘 or the one at
position 𝑥𝑘 + 1, 𝑦𝑘 − 1 is closer to circle boundary.
Derivation Midpoint Circle
Algorithm
• So for finding which pixel is more closer using
decision parameter evaluated at the midpoint
between two candidate pixels as below:
• 𝑝𝑘 = 𝑓𝑐𝑖𝑟𝑐𝑙𝑒 𝑥𝑘 + 1, 𝑦𝑘 − 12
2 2
• 𝑝𝑘 = 𝑥𝑘 + 1 + 𝑦𝑘 − 1
2
− 𝑟2
• If 𝑝𝑘 < 0, midpoint is inside the circle and the pixel
on the scan line 𝑦𝑘 is closer to circle boundary.
• Otherwise midpoint is outside or on the boundary
and we select the scan line 𝑦𝑘 − 1.
Contd.
• Successive decision parameters are obtain using incremental calculations as follows:
• 𝑝𝑘+1 = 𝑓𝑐𝑖𝑟𝑐𝑙𝑒 𝑥𝑘+1 + 1, 𝑦𝑘+1 − 12
2 2
• 𝑝𝑘+1 = 𝑥𝑘 + 1 + 1 + 𝑦𝑘+1 − 12 − 𝑟2
• Now we can obtain recursive calculation using equation of 𝑝𝑘+1 and 𝑝𝑘 as follow
2 2 2
• 𝑝𝑘+1 − 𝑝𝑘 = 𝑥𝑘 + 1 + 1 + 𝑦𝑘+1 − 12 − 𝑟2 − 𝑥𝑘 + 1 2
+ 𝑦𝑘 − 12 − 𝑟2
2
• 𝑝𝑘+1 − 𝑝𝑘 = 𝑥𝑘 + 1 + 2 𝑥𝑘 + 1 + 1 + 𝑦𝑘+1 2 − 𝑦𝑘+1 + 14 − 𝑟 2 − 𝑥𝑘 + 1 2
− 𝑦𝑘 2 + 𝑦𝑘 − 14 + 𝑟 2
Contd.
2
• 𝑝𝑘+1 − 𝑝𝑘 = 𝑥𝑘 + 1 + 2 𝑥𝑘 + 1 + 1 + 𝑦𝑘+1 2 − 𝑦𝑘+1 + 14 − 𝑟 2 − 𝑥𝑘 + 1 2
− 𝑦𝑘 2 + 𝑦𝑘 − 14 + 𝑟 2
• 𝑝𝑘+1 − 𝑝𝑘 = 2 𝑥𝑘 + 1 + 1 + 𝑦𝑘+1 2 − 𝑦𝑘+1 − 𝑦𝑘 2 + 𝑦𝑘
• 𝑝𝑘+1 − 𝑝𝑘 = 2 𝑥𝑘 + 1 + (𝑦𝑘+1 2 − 𝑦𝑘 2 ) − (𝑦𝑘+1 −𝑦𝑘 ) + 1
• 𝑝𝑘+1 = 𝑝𝑘 + 2 𝑥𝑘 + 1 + (𝑦𝑘+1 2 − 𝑦𝑘 2 ) − (𝑦𝑘+1 −𝑦𝑘 ) + 1
• Now we can put 2𝑥𝑘+1 = 2(𝑥𝑘 + 1)
• 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + (𝑦𝑘+1 2 − 𝑦𝑘 2 ) − (𝑦𝑘+1 −𝑦𝑘 ) + 1
Contd.
• 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + (𝑦𝑘+1 2 − 𝑦𝑘 2 ) − (𝑦𝑘+1 −𝑦𝑘 ) + 1
• In above equation 𝑦𝑘+1 is either 𝑦𝑘 or 𝑦𝑘 − 1 depending on the sign of the
𝑝𝑘 .
• If we select 𝑦𝑘+1 = 𝑦𝑘 .
• 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + 1
• If we select 𝑦𝑘+1 = 𝑦𝑘 – 1.
• 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + (𝑦𝑘+1 2 − 𝑦𝑘 2 ) − (𝑦𝑘+1 −𝑦𝑘 ) + 1
• 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + (𝑦𝑘+1 +𝑦𝑘 )(𝑦𝑘+1 −𝑦𝑘 ) − (𝑦𝑘+1 −𝑦𝑘 ) + 1
• 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + (𝑦𝑘 – 1 + 𝑦𝑘 )(𝑦𝑘 – 1 − 𝑦𝑘 ) − (𝑦𝑘 – 1 − 𝑦𝑘 ) + 1
• 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + (2𝑦𝑘 – 1)(– 1) − (– 1) + 1
Contd.
• 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 − 2𝑦𝑘 + 1 + 1 + 1
• 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 − (2𝑦𝑘 − 2) + 1
• Now put 2𝑦𝑘+1 = 2𝑦𝑘 − 2.
• 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 − 2𝑦𝑘+1 + 1
IDP Midpoint Circle Algorithm
• The initial decision parameter(IDP) is obtained by
evaluating the circle function at the start position
𝑥0 , 𝑦0 = (0, 𝑟) as follows.
• 𝑝0 = 𝑓𝑐𝑖𝑟𝑐𝑙𝑒 0 + 1, 𝑟 − 12
2
• 𝑝0 = 12 + 𝑟− 1
2
− 𝑟2
• 𝑝0 = 1 + 𝑟 2 − 𝑟 + 14 − 𝑟 2
• 𝑝0 = 54 − 𝑟
• 𝑝0 ≈ 1 − 𝑟
Algorithm for Midpoint Circle Generation
1. Input radius r and circle center (𝑥𝑐 , 𝑦𝑐 ), and obtain the first point on the
circumference of a circle centered on the origin as
𝑥0 , 𝑦0 = (0, 𝑟)
2. calculate the initial value of the decision parameter as
𝑝0 = 54 − 𝑟
3. At each 𝑥𝑘 position, starting at 𝑘 = 0, perform the following test:
If 𝑝𝑘 < 0, the next point along the circle centered on (0, 0) is 𝑥𝑘 + 1, 𝑦𝑘 &
𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + 1
Otherwise, the next point along the circle is 𝑥𝑘 + 1, 𝑦𝑘 − 1 &
𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + 1 − 2𝑦𝑘+1
Where 2𝑥𝑘+1 = 2𝑥𝑘 + 2, & 2𝑦𝑘+1 = 2𝑦𝑘 − 2.
4. Determine symmetry points in the other seven octants.
5. Move each calculated pixel position (𝑥, 𝑦) onto the circular path centered on
(𝑥𝑐 , 𝑦𝑐 ) and plot the coordinate values:
𝑥 = 𝑥 + 𝑥𝑐 , 𝑦 = 𝑦 + 𝑦𝑐
6. Repeat steps 3 through 5 until 𝑥 ≥ 𝑦.
Example Midpoint Circle
Algorithm
• Example: Draw circle with radius 𝑟 = 10, and center of
circle is 1, 1 (Only one octant 𝑥 = 0 to 𝑥 = 𝑦 )
• First we find pixel position for octant 𝑥 = 0 to 𝑥 = 𝑦 for
center 0, 0
𝒌 𝒑𝒌 (𝒙𝒌+𝟏 , 𝒚𝒌+𝟏 )
• 𝑝0 = 1 − 𝑟 0 -9 (1, 10)
• 𝑝0 = 1 − 10 = −9 1 -6 (2, 10)

• Now 𝑝0 < 0 we select (1, 10) 2 -1 (3, 10)


3 6 (4, 9)
• 𝑝1 = 𝑝0 + 2𝑥1 + 1
4 -3 (5, 9)
• 𝑝1 = −9 + 2 + 1 = −6 5 8 (6, 8)
• Now 𝑝1 < 0 we select (2, 10) 6 5 (7, 7)
Contd. 𝒌 𝒑𝒌 (𝒙𝒌+𝟏 , 𝒚𝒌+𝟏 )
0 -9 (1, 10)
• 𝑝2 = 𝑝1 + 2𝑥2 + 1 1 -6 (2, 10)
2 -1 (3, 10)
• 𝑝2 = −6 + 4 + 1 = −1
3 6 (4, 9)
• Now 𝑝2 < 0 we select (3, 10) 4 -3 (5, 9)
• 𝑝3 = 𝑝2 + 2𝑥3 + 1 5 8 (6, 8)

• 𝑝3 = −1 + 6 + 1 = 6 6 5 (7, 7)

• Now 𝑝3 ≮ 0 we select (4, 9)


• 𝑝4 = 𝑝3 + 2𝑥4 + 1 − 2𝑦4
• 𝑝4 = 6 + 8 + 1 − 18 = −3
• Now 𝑝4 < 0 we select (5, 9)
Contd. 𝒌 𝒑𝒌 (𝒙𝒌+𝟏 , 𝒚𝒌+𝟏 )
0 -9 (1, 10)
• 𝑝5 = 𝑝4 + 2𝑥5 + 1 1 -6 (2, 10)
2 -1 (3, 10)
• 𝑝5 = −3 + 10 + 1 = 8
3 6 (4, 9)
• Now 𝑝5 ≮ 0 we select (6, 8) 4 -3 (5, 9)

• 𝑝6 = 𝑝5 + 2𝑥6 + 1 − 2𝑦6 5 8 (6, 8)


6 5 (7, 7)
• 𝑝6 = 8 + 12 + 1 − 16 = 5
• Now 𝑝6 ≮ 0 we select (7, 7)
• Now Loop exit as 𝑥 ≥ 𝑦, as
• in our case 7 ≥ 7
Contd.
• Than we calculate pixel position for given center 1, 1
using equations: Center (0, 0) Center (1, 1)
• 𝑥 = 𝑥 + 𝑥𝑐 = 𝑥 + 1 (1, 10) (2, 11)
• 𝑦 = 𝑦 + 𝑦𝑐 = 𝑦 + 1 (2, 10) (3, 11)
(3, 10) (4, 11)
(4, 9) (5, 10)
(5, 9) (6, 10)
(6, 8) (7, 9)
(7, 7) (8, 8)
Contd.
• Plot the pixel.
12
• First plot initial point. 11
(1, 11) 10
9
Center (1, 1)
8
(2, 11) 7
6
(3, 11)
5
(4, 11) 4
(5, 10) 3
(6, 10) 2
Center
1
(7, 9) (1, 1)
0
(8, 8)
0 1 2 3 4 5 6 7 8 9 10 11
Properties of Circle- Symmetry
• Computation can be reduced by considering symmetry city property of circles.
• The shape of circle is similar in each octant.
(-3, 4) (3, 4)
(-Y, X) (Y, X)
(-4, 3) (4, 3)
(-X, Y) (X, Y)
45𝑂
(-4, -3) (4, -3)
(-X, -Y) (X, -Y)

(-Y, -X) (Y, -X)


(-3, -4) (3, -4)
Ellipse
• AN ellipse is defined as the set of points such that
the sum of the distances from two fixed positions
(foci) is same for all points.
𝑝(𝑥, 𝑦)
𝑑1
𝑑2
𝑓1 𝑓2
Properties of Ellipse-Symmetry
• Symmetry property further reduced computations.
• An ellipse in standard position is symmetric
between quadrant.
(−2, 4) (2, 4)
(−𝑥, 𝑦) (𝑥, 𝑦)
𝑟𝑦
𝑟𝑥
(𝑥𝑐 , 𝑦𝑐 )

(−𝑥, −𝑦) (𝑥, −𝑦)


(−2, −4) (2, −4)
Introduction to Midpoint Ellipse Algorithm
• Given parameters 𝑟𝑥 , 𝑟𝑦 , & (𝑥𝑐 , 𝑦𝑐 ).
• We determine points (𝑥, 𝑦) for an ellipse in standard position
centered on the origin.
• Then we shift the points so the ellipse is centered at (𝑥𝑐 , 𝑦𝑐 ).
• If we want to display the ellipse in nonstandard position then we
rotate the ellipse about its center to align with required direction.
• For the present we consider only the standard position.
• We draw ellipse in first quadrant and than use symmetry property for
other three quadrant.
Regions in Midpoint Ellipse Algorithm
• In this method we divide first quadrant into two parts according to
the slope of an ellipse Region 1
𝑦
• Boundary divides region at 𝑆𝑙𝑜𝑝𝑒 = −1
• slope = -1.
𝑟𝑦
• We take unit step in X direction Region 2
• If magnitude of ellipse slope < 1 (Region 1). 𝑟𝑥 𝑥
• We take unit step in Y direction
• If magnitude of ellipse slope > 1 (Region 2).
Ways of Processing Midpoint Ellipse Algorithm

• We can start from (0, 𝑟𝑦 ) and step clockwise along the elliptical path
in the first quadrant
• Alternatively, we could start at (𝑟𝑥 , 0 ) and select points in a
counterclockwise order.
• With parallel processors, we could calculate pixel positions in the two
regions simultaneously.
• Here we consider sequential implementation of midpoint algorithm.
• We take the start position at (0, 𝑟𝑦 ) and steps along the elliptical path
in clockwise order through the first quadrant.
Decision Parameter Midpoint Ellipse Algorithm
• We define ellipse function for center of ellipse at (0, 0) as follows.
• 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥, 𝑦 = 𝑟𝑦 2 𝑥 2 + 𝑟𝑥 2 𝑦 2 − 𝑟𝑦 2 𝑟𝑥 2
• Which has the following properties:
<0 𝑖𝑓 𝑥, 𝑦 𝑖𝑠 𝑖𝑛𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥, 𝑦 = 0 𝑖𝑓 𝑥, 𝑦 𝑖𝑠 𝑜𝑛 𝑡ℎ𝑒 𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
> 0 𝑖𝑓 𝑥, 𝑦 𝑖𝑠 𝑜𝑢𝑡𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
• Thus the ellipse function serves as the decision parameter in the
midpoint ellipse algorithm.
• At each sampling position we select the next pixel from two
candidate pixel.
Processing Steps of Midpoint Ellipse Algorithm

• Starting at (0, 𝑟𝑦 ) we take unit step in 𝑥 direction until


we reach the boundary between region-1 and region-2.
• Then we switch to unit steps in 𝑦 direction in remaining
portion on ellipse in first quadrant. Region 1
𝑦
𝑆𝑙𝑜𝑝𝑒 = −1
 At each step we need to test the value 𝑟𝑦
of the slope of the curve for deciding Region 2
the end point of the region-1. 𝑟𝑥 𝑥
Decide Boundary between Region 1 and 2
• The ellipse slope is calculated using following
equation.
𝑑𝑦 2𝑟𝑦 2 𝑥
• =−
𝑑𝑥 2𝑟𝑥 2 𝑦
• At boundary between region 1 and 2 slope= -1 and
equation become.
• 2𝑟𝑦 2 𝑥 = 2𝑟𝑥 2 𝑦
• Therefore we move out of region 1 whenever
following equation is false:
• 2𝑟𝑦 2 𝑥 ≤ 2𝑟𝑥 2 𝑦
Midpoint between Candidate pixel in Region 1
• Figure shows the midpoint between the two candidate pixels at sampling position
𝑥𝑘 + 1 in the first region.
ry2x2+rx2y2-rx2ry2=0

yk Midpoint

yk-1 Candidate
Pixel

xk xk+1 xk+2

• Assume we are at (𝑥𝑘 , 𝑦𝑘 ) position and we determine the next position along the
ellipse path, by evaluating decision parameter at midpoint between two candidate
pixels.
1
• 𝑝1𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥𝑘 + 1, 𝑦𝑘 −
2
Derivation for Region 1
1
• 𝑝1𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥𝑘 + 1, 𝑦𝑘 −
2
1 2
• 𝑝1𝑘 = 𝑟𝑦 2 (𝑥𝑘 + 1)2 +𝑟𝑥 2 𝑦𝑘 − − 𝑟𝑥 2 𝑟𝑦 2
2
• If 𝑝1𝑘 < 0, the midpoint is inside the ellipse and
the pixel on scan line 𝑦𝑘 is closer to ellipse
boundary
• Otherwise the midpoint is outside or on the ellipse
boundary and we select the pixel 𝑦𝑘 − 1.
Contd.
• At the next sampling position decision parameter for region 1 is evaluated as.
1
• 𝑝1𝑘+1 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥𝑘+1 + 1, 𝑦𝑘+1 −
2

2 2 2 1 2
• 𝑝1𝑘+1 = 𝑟𝑦 𝑥𝑘 + 1 + 1 + 𝑟𝑥 𝑦𝑘+1 − − 𝑟𝑥 2 𝑟𝑦 2
2
• Now subtract 𝑝1𝑘 from 𝑝1𝑘+1
1 2 1 2
• 𝑝1𝑘+1 − 𝑝1𝑘 = 𝑟𝑦 2 𝑥𝑘 + 1 + 1 2
+ 𝑟𝑥 2 𝑦𝑘+1 − − 𝑟𝑥 2 𝑟𝑦 2 − 𝑟𝑦 2 (𝑥𝑘 + 1)2 −𝑟𝑥 2 𝑦𝑘 − + 𝑟𝑥 2 𝑟𝑦 2
2 2
Contd.
2 2 2 1 2 2 2 2 1 2
• 𝑝1𝑘+1 − 𝑝1𝑘 = 𝑟𝑦 𝑥𝑘 + 1 + 1 + 𝑟𝑥 𝑦𝑘+1 − − 𝑟𝑦 (𝑥𝑘 + 1) −𝑟𝑥 𝑦𝑘 −
2 2

2 2 2 2 2 1 2 2 2 2 1 2
• 𝑝1𝑘+1 − 𝑝1𝑘 = 𝑟𝑦 𝑥𝑘 + 1 + 2𝑟𝑦 𝑥𝑘 + 1 + 𝑟𝑦 + 𝑟𝑥 𝑦𝑘+1 − − 𝑟𝑦 (𝑥𝑘 + 1) −𝑟𝑥 𝑦𝑘 −
2 2
1 2 1 2
• 𝑝1𝑘+1 − 𝑝1𝑘 = 2𝑟𝑦 2 𝑥𝑘 + 1 + 𝑟𝑦 2 + 𝑟𝑥 2 𝑦𝑘+1 − − 𝑦𝑘 −
2 2

• Now making 𝑝1𝑘+1 as subject.


2 2 2 1 2 1 2
• 𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 𝑥𝑘 + 1 + 𝑟𝑦 + 𝑟𝑥 𝑦𝑘+1 − − 𝑦𝑘 −
2 2
Contd.
1 2 1 2
• 𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘 + 1 + 𝑟𝑦 2 + 𝑟𝑥 2 𝑦𝑘+1 − − 𝑦𝑘 −
2 2
• 𝑦𝑘+1 is either 𝑦𝑘 or 𝑦𝑘 − 1, depends on the sign of 𝑝1𝑘
IDP for Region 1
• Now we calculate the initial decision parameter
𝑝10 by putting 𝑥0 , 𝑦0 = (0, 𝑟𝑦 ) as follow.
1
• 𝑝10 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 0 + 1, 𝑟𝑦 −
2
1 2
• 𝑝10 = 𝑟𝑦 2 (1)2 +𝑟𝑥 2 𝑟𝑦 − − 𝑟𝑥 2 𝑟𝑦 2
2
1 2
• 𝑝10 = 𝑟𝑦 2 + 𝑟𝑥 2 𝑟𝑦 − − 𝑟𝑥 2 𝑟𝑦 2
2
1 2
• 𝑝10 = 𝑟𝑦 2 − 2
𝑟𝑥 𝑟𝑦 + 𝑟𝑥
4
Midpoint between Candidate pixel in Region 2
• Now we similarly calculate over region-2.
• Unit stepping in negative 𝑦 direction and the midpoint is now
taken between horizontal pixels at each step.
ry2x2+rx2y2-rx2ry2=0

yk Midpoint
yk-1 Candidate
Pixel
xk xk+1 xk+2

• For this region, the decision parameter is evaluated as follows.


1
• 𝑝2𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥𝑘 + , 𝑦𝑘 −1
2
Derivation for Region 2
1
• 𝑝2𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥𝑘 + , 𝑦𝑘 −1
2
1 2
• 𝑝2𝑘 = 𝑟𝑦 2 𝑥𝑘 + + 𝑟𝑥 2 𝑦𝑘 − 1 2
− 𝑟𝑥 2 𝑟𝑦 2
2
• If 𝑝2𝑘 > 0 the midpoint is outside the ellipse
boundary, and we select the pixel at 𝑥𝑘 .
• If 𝑝2𝑘 ≤ 0 the midpoint is inside or on the ellipse
boundary and we select 𝑥𝑘 + 1.
Contd.
• At the next sampling position decision parameter for region 2 is evaluated as.
1
• 𝑝2𝑘+1 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥𝑘+1 + 2 , 𝑦𝑘+1 − 1

2 1 2
• 𝑝2𝑘+1 = 𝑟𝑦 𝑥𝑘+1 + + 𝑟𝑥 2 𝑦𝑘 − 1 − 1 2
− 𝑟𝑥 2 𝑟𝑦 2
2
• Now subtract 𝑝2𝑘 from 𝑝2𝑘+1
2 1 2 2 2 1 2
• 𝑝2𝑘+1 − 𝑝2𝑘 = 𝑟𝑦 𝑥𝑘+1 + + 𝑟𝑥 𝑦𝑘 − 1 − 1 − 𝑟𝑥 2 𝑟𝑦 2 − 𝑟𝑦 2 𝑥𝑘 + − 𝑟𝑥 2 𝑦𝑘 − 1 2 + 𝑟𝑥 2 𝑟𝑦 2
2 2
Contd.
2 1 2 2 2 2 2 2 1 2
• 𝑝2𝑘+1 − 𝑝2𝑘 = 𝑟𝑦 𝑥𝑘+1 + + 𝑟𝑥 𝑦𝑘 − 1 − 1 − 𝑟𝑥 𝑟𝑦 − 𝑟𝑦 𝑥𝑘 + − 𝑟𝑥 2 𝑦𝑘 − 1 2
+ 𝑟𝑥 2 𝑟𝑦 2
2 2

2 1 2 2 2 2 2 2 1 2
• 𝑝2𝑘+1 − 𝑝2𝑘 = 𝑟𝑦 𝑥𝑘+1 + + 𝑟𝑥 𝑦𝑘 − 1 − 2𝑟𝑥 𝑦𝑘 − 1 + 𝑟𝑥 − 𝑟𝑦 𝑥𝑘 + − 𝑟𝑥 2 𝑦𝑘 − 1 2
2 2
1 2 1 2
• 𝑝2𝑘+1 − 𝑝2𝑘 = 𝑟𝑦 2 𝑥𝑘+1 + − 2𝑟𝑥 2 𝑦𝑘 − 1 + 𝑟𝑥 2 − 𝑟𝑦 2 𝑥𝑘 +
2 2
1 2 1 2
• 𝑝2𝑘+1 − 𝑝2𝑘 = −2𝑟𝑥 2 𝑦𝑘 − 1 + 𝑟𝑥 2 + 𝑟𝑦 2 𝑥𝑘+1 + − 𝑥𝑘 +
2 2
Contd.
1 2 1 2
• 𝑝2𝑘+1 − 𝑝2𝑘 = −2𝑟𝑥 2 𝑦𝑘 − 1 + 𝑟𝑥 2 + 𝑟𝑦 2 𝑥𝑘+1 + − 𝑥𝑘 +
2 2
• Now making 𝑝2𝑘+1 as subject.
1 2 1 2
• 𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥 2 𝑦𝑘 − 1 + 𝑟𝑥 2 + 𝑟𝑦 2 𝑥𝑘+1 + − 𝑥𝑘 +
2 2
• Here 𝑥𝑘+1 is either 𝑥𝑘 or 𝑥𝑘 + 1, depends on the sign of 𝑝2𝑘 .
IDP for Region 2
• In region-2 initial position is selected which is last
position of region one and the initial decision
parameter is calculated as follows.
1
• 𝑝20 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥0 + , 𝑦0 −1
2
2 1 2
• 𝑝20 = 𝑟𝑦 𝑥0 + + 𝑟𝑥 2 𝑦0 − 1 2 − 𝑟𝑥 2 𝑟𝑦 2
2
• For simplify calculation of 𝑝20 we could also select
pixel position in counterclockwise order starting at
(𝑟𝑥 , 0).
Algorithm for Midpoint Ellipse Generation
1. Input 𝑟𝑥 , 𝑟𝑦 and ellipse center (𝑥𝑐 , 𝑦𝑐 ), and obtain the first point on an ellipse
centered on the origin as
𝑥0 , 𝑦0 = (0, 𝑟𝑦 )

2. Calculate the initial value of the decision parameter in region 1 as


1
𝑝10 = 𝑟𝑦 2 − 𝑟𝑥 2 𝑟𝑦 + 𝑟𝑥 2
4

3. At each 𝑥𝑘 position in region 1, starting at 𝑘 = 0, perform the following test:


If 𝑝1𝑘 < 0, than the next point along the ellipse is (𝑥𝑘+1 , 𝑦𝑘 ) and
𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘+1 + 𝑟𝑦 2

Otherwise, the next point along the ellipse is (𝑥𝑘+1 , 𝑦𝑘 − 1) and


𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘+1 + 𝑟𝑦 2 − 2𝑟𝑥 2 𝑦𝑘+1
With
2𝑟𝑦 2 𝑥𝑘+1 = 2𝑟𝑦 2 𝑥𝑘 + 2𝑟𝑦 2 , 2𝑟𝑥 2 𝑦𝑘+1 = 2𝑟𝑥 2 𝑦𝑘 − 2𝑟𝑥 2
And continue until 2𝑟𝑦 2 𝑥 ≤ 2𝑟𝑥 2 𝑦
Contd.
4. Calculate the initial value of the decision parameter in region 2 using the last
point 𝑥0 , 𝑦0 calculated in region 1 as
2 1 2
𝑝20 = 𝑟𝑦 𝑥0 + + 𝑟𝑥 2 𝑦0 − 1 2 − 𝑟𝑥 2 𝑟𝑦 2
2

5. At each 𝑦𝑘 position in region-2, starting at 𝑘 = 0, perform the following test:


If 𝑝2𝑘 > 0, the next point along the ellipse is (𝑥𝑘 , 𝑦𝑘 − 1) and
𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥 2 𝑦𝑘+1 + 𝑟𝑥 2

Otherwise, the next point along the ellipse is (𝑥𝑘 + 1, 𝑦𝑘 − 1) and


𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥 2 𝑦𝑘+1 + 𝑟𝑥 2 + 2𝑟𝑦 2 𝑥𝑘+1
Using the same incremental calculations for 𝑥 and 𝑦 as in region 1.

6. Determine symmetry points in the other three quadrants.

7. Move each calculated pixel position (𝑥, 𝑦) onto the elliptical path centered on
(𝑥𝑐 , 𝑦𝑐 ) and plot the coordinate values:
𝑥 = 𝑥 + 𝑥𝑐 , 𝑦 = 𝑦 + 𝑦𝑐

8. Repeat the steps for region 2 until 𝑦𝑘 ≥ 0.


Example Midpoint Ellipse Algorithm
• Example: Calculate intermediate pixel position (For first quadrant)
for ellipse with 𝑟𝑥 = 8, 𝑟𝑦 = 6 and ellipse center is at origin
• Initial point 0, 𝑟𝑦 = (0, 6)
2 1 2
• 𝑝10 = 𝑟𝑦 − 𝑟𝑥 2 𝑟𝑦
+ 𝑟𝑥
4
1
• 𝑝10 = 62 − 82 ∗ 6 + 82
4
• 𝑝10 = −332
Contd.
 𝑝10 = −332 K p1k (xk+1, yk+1)
0 -332 (1, 6)
2 2 2 1 2 1 2
 𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 𝑥𝑘 + 1 + 𝑟𝑦 + 𝑟𝑥 𝑦𝑘+1 − − 𝑦𝑘 −
2 2 1 -224 (2, 6)
2 -44 (3, 6)
1 2 1 2
 𝑝11 = −332 + 2 ∗ 62 0+1 + 62 + 82 6− − 6− = −224
2 2 3 208 (4, 5)
4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)

Calculation stop when 𝐼𝑓 𝑝1𝑘 < 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘


2𝑟𝑦 2 𝑥 > 2𝑟𝑥 2 𝑦 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘 − 1
Contd.
 2
𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 𝑥𝑘 + 1 + 𝑟𝑦 + 𝑟𝑥2 2
𝑦𝑘+1 −
1 2
− 𝑦𝑘 −
1 2 K p1k (xk+1, yk+1)
2 2
0 -332 (1, 6)
 𝑝12 = −224 + 2 ∗ 62 1+1 + 62 + 82 6−
1 2
− 6−
1 2
= −44 1 -224 (2, 6)
2 2
2 -44 (3, 6)
3 208 (4, 5)
4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)

Calculation stop when 𝐼𝑓 𝑝1𝑘 < 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘


2𝑟𝑦 2 𝑥 > 2𝑟𝑥 2 𝑦 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘 − 1
Contd.
 2
𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 𝑥𝑘 + 1 + 𝑟𝑦 + 𝑟𝑥 2 2
𝑦𝑘+1 −
1 2
− 𝑦𝑘 −
1 2 K p1k (xk+1, yk+1)
2 2
0 -332 (1, 6)
 𝑝13 = −44 + 2 ∗ 62 2+1 + 62 + 82 6−
1 2
− 6
1 2
−2 = 208 1 -224 (2, 6)
2
2 -44 (3, 6)
3 208 (4, 5)
4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)

Calculation stop when 𝐼𝑓 𝑝1𝑘 < 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘


2𝑟𝑦 2 𝑥 > 2𝑟𝑥 2 𝑦 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘 − 1
Contd.

 2
𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 𝑥𝑘 + 1 + 𝑟𝑦 + 𝑟𝑥 2 2
𝑦𝑘+1 −
1 2
− 𝑦𝑘 −
1 2 K p1k (xk+1, yk+1)
2 2
0 -332 (1, 6)
 𝑝14 = 208 + 2 ∗ 62 3+1 + 62 + 82 5−
1 2
− 6−
1 2
= −108 1 -224 (2, 6)
2 2
2 -44 (3, 6)
3 208 (4, 5)
4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)

Calculation stop when 𝐼𝑓 𝑝1𝑘 < 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘


2𝑟𝑦 2 𝑥 > 2𝑟𝑥 2 𝑦 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘 − 1
Contd.
 𝑝1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘 + 1 + 𝑟𝑦 2 +
𝑘+1 K p1k (xk+1, yk+1)
1 2 1 2
𝑟𝑥 2 𝑦𝑘+1 −
2
− 𝑦𝑘 −
2
0 -332 (1, 6)
1 -224 (2, 6)
 𝑝15 = −108 + 2 ∗ 62 4 + 1 + 62 +
2 -44 (3, 6)
1 2 1 2
82 5− − 5− = 288 3 208 (4, 5)
2 2

4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)

Calculation stop when 𝐼𝑓 𝑝1𝑘 < 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘


2𝑟𝑦 2 𝑥 > 2𝑟𝑥 2 𝑦 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘 − 1
Contd.
 𝑝1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘 + 1 + 𝑟𝑦 2 +
𝑘+1 K p1k (xk+1, yk+1)
1 2 1 2
𝑟𝑥 2 𝑦𝑘+1 −
2
− 𝑦𝑘 −
2
0 -332 (1, 6)
1 -224 (2, 6)
 𝑝16 = 288 + 2 ∗ 62 5 + 1 + 62 +
2 -44 (3, 6)
1 2 1 2
82 4− − 5− = 244 3 208 (4, 5)
2 2

4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)

Calculation stop when 𝐼𝑓 𝑝1𝑘 < 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘


2𝑟𝑦 2 𝑥 > 2𝑟𝑥 2 𝑦 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘 − 1
Contd.
1 2
K p2k (xk+1, yk+1)
 𝑝20 = 𝑟𝑦 2 𝑥0 + + 𝑟𝑥 2 𝑦0 − 1 2 − 𝑟𝑥 2 𝑟𝑦 2
2
0 -23 (8, 2)
1 2
1 361 (8, 1)
 𝑝20 = 62 7+ + 82 3 − 1 2 − 82 62 = −23
2 2 297 (8, 0)

Calculation stop when 𝐼𝑓 𝑝2𝑘 > 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑥𝑘+1 = 𝑥𝑘


𝑦𝑘 ≤ 0 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑥𝑘+1 = 𝑥𝑘 + 1
Contd.
2 2 2 1 2 1 2 K p2k (xk+1, yk+1)
 𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥 𝑦𝑘 − 1 + 𝑟𝑥 + 𝑟𝑦 𝑥𝑘+1 + − 𝑥𝑘 +
2 2
0 -23 (8, 2)
2 2 2 1 2 1 2 1 361 (8, 1)
 𝑝21 = −23 − 2 ∗ 8 3−1 +8 +6 8+ 2
− 7+ 2
= 361
2 297 (8, 0)

Calculation stop when 𝐼𝑓 𝑝2𝑘 > 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑥𝑘+1 = 𝑥𝑘


𝑦𝑘 ≤ 0 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑥𝑘+1 = 𝑥𝑘 + 1
Contd.
 2
𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥 𝑦𝑘 − 1 + 𝑟𝑥 + 𝑟𝑦 2 2
𝑥𝑘+1 +
1 2
− 𝑥𝑘 +
1 2 K p2k (xk+1, yk+1)
2 2
0 -23 (8, 2)
 𝑝22 = 361 − 2 ∗ 82 2−1 + 82 + 62 8
1 2
+2 − 8+
1 2
= 297 1 361 (8, 1)
2
2 297 (8, 0)

Calculation stop when 𝐼𝑓 𝑝2𝑘 > 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑥𝑘+1 = 𝑥𝑘


𝑦𝑘 ≤ 0 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑥𝑘+1 = 𝑥𝑘 + 1
Contd.
• Plot the pixel.
• Plot initial point(0, 6) 12
11
10
Center (0, 0) Center (0, 0) 9
8
(1, 6) (8, 2) 7
(2, 6) 6
(8, 1)
5
(3, 6) (8, 0) 4
(4, 5) 3
2
(5, 5) 1
(6, 4) 0

(7, 3)
Center
(0, 0) 0 1 2 3 4 5 6 7 8 9 10 11
1. What is scan conversion in computer graphics?
a) Converting a vector image into raster format
b) Converting an image from grayscale to color
c) Converting raster graphics into vector graphics
d) Converting an image into a 3D model

Answer: a) Converting a vector image into raster format


2. Which of the following algorithms is commonly used for
line drawing in scan conversion?
a) Dijkstra's Algorithm
b) Bresenham’s Line Algorithm
c) Kruskal’s Algorithm
d) Liang Barsky Algorithm
Answer: b) Bresenham’s Line Algorithm

3. What is the main advantage of using Bresenham's Line Algorithm?


a) It uses floating-point arithmetic for accuracy.
b) It eliminates the need for floating-point calculations.
c) It is slower but more accurate than the Digital Differential Analyzer (DDA).
d) It works only for horizontal lines.
Answer: b) It eliminates the need for floating-point calculations.
4. In scan conversion, aliasing refers to:
a) Smooth rendering of lines
b) The jagged appearance of lines due to pixelation
c) Reducing the size of an image
d) Blurring of raster images
Answer: b) The jagged appearance of lines due to pixelation
5. Which algorithm is commonly used for circle drawing in scan conversion?
a) DDA Algorithm
b) Midpoint Circle Algorithm
c) Prim’s Algorithm
d) Bresenham’s Line Algorithm
Answer: b) Midpoint Circle Algorithm

6. The Digital Differential Analyzer (DDA) algorithm calculates points on a line using:
a) Integer arithmetic
b) Floating-point arithmetic
c) Polar coordinates
d) Binary arithmetic
Answer: b) Floating-point arithmetic
8. What is the purpose of anti-aliasing in scan conversion?
a) To fill polygons with a solid color
b) To make lines look smoother by reducing the jagged edges
c) To draw a line between two points using a straight-line equation
d) To calculate intersections between line segments
Answer: b) To make lines look smoother by reducing the jagged edges

9. In the midpoint circle algorithm, the initial decision parameter p0 is


calculated as:
a) p0=1−r
b) p0=r−1
c) p0=1/r
d) p0=r+1
Answer: a) p0=1−r
1. Components of Graphics Hardware

1.Graphics Processing Unit (GPU):


1. A specialized processor optimized for rendering graphics.
2. Performs parallel processing for tasks like shading, lighting, and texture mapping.
3. Modern GPUs, like those from NVIDIA and AMD, support AI and compute tasks.

2.Video Memory (VRAM):


1. High-speed memory used to store image data, textures, and frame buffers.
2. GDDR (Graphics Double Data Rate) memory is common in modern GPUs.

3.Frame Buffer:
1. A portion of memory containing the complete image to be displayed.
2. Includes color, depth (Z-buffer)

4.Display Devices:
1. Hardware like monitors, projectors, and VR headsets.
2. Technologies include CRT, LCD, LED, OLED, and MicroLED.

5.Input/Output Interfaces:
1. Interfaces like HDMI, DisplayPort, and USB-C connect GPUs to display devices.
2. Types of Graphics Hardware

1.Integrated Graphics:
1. Built into the CPU or motherboard.
2. Cost-effective but limited in performance.
3. Examples: Intel UHD Graphics, AMD Radeon Vega.

2.Dedicated Graphics Cards:


1. Standalone cards with powerful GPUs and dedicated VRAM.
2. Ideal for gaming, 3D rendering, and machine learning.
3. Examples: NVIDIA GeForce, AMD Radeon.

3.Workstation GPUs:
1. Designed for professional use in CAD, simulation, and AI.
2. Examples: NVIDIA Quadro, AMD Radeon Pro.

4.Mobile GPUs:
1. Integrated or discrete GPUs optimized for laptops and handheld devices.
2. Examples: NVIDIA GeForce RTX Mobile, Apple M-series GPUs.
1.Which component in a computer system is primarily responsible for rendering graphics?
a) CPU
b) GPU
c) RAM
Answer: b) GPU
d) SSD

2.What does GPU stand for?


a) General Processing Unit
b) Graphical Processing Unit
c) Graphics Processing Unit Answer: c) Graphics Processing Unit
d) Grid Processing Unit

3.Which of the following is NOT a type of graphics hardware?


a) Integrated GPU
b) Discrete GPU
c) Network Interface Card
d) External GPU Answer: c) Network Interface Card

4.Which company is a major manufacturer of GPUs?


a) Intel
b) NVIDIA
c) AMD
d) All of the above Answer: d) All of the above
1/28/2025 Associate Professor Sujan Shrestha

You might also like