SlideShare a Scribd company logo
Rendering – 1
(Scan Conversion of Line and Circle)
Lenin Laitonjam
NIT Mizoram
Computer Grapics - CSL 1603
Rendering
• To draw something on the screen, we need to consider
pixel grid
• Discreet space
• We need to map the representations from continuous to
discreet space
• The mapping process is called rendering
• Also called scan conversion/rasterization
• We will have a look at scan conversion of
• Point
• Line
• Circle
Rendering
Computer Grapics - CSL 1603
Point Scan Conversion
•Trivial: simply round off to the nearest pixel
position
The point can be mapped to
any of the four pixel
positions, depending on the
coordinate value
e.g. (1.1, 2.6) maps to (1, 3)
Rendering
Computer Grapics - CSL 1603
Line Scan Conversion
• A line segment is defined by the coordinate
positions of the line end-points
• What happens when we try to draw this on a
pixel based display?
• How to choose the correct pixels
Rendering
Computer Grapics - CSL 1603
Line Equation
• Slope-intercept line
equation
where
x
y
y0
yend
xend
x0
b
x
m
y 


0
0
x
x
y
y
m
end
end



0
0 x
m
y
b 


Rendering
Computer Grapics - CSL 1603
A Very Simple Solution
• Simply work out the corresponding y coordinate
for each unit x coordinate
• Let’s consider the following example
x
y
(2, 2)
(7, 5)
2 7
2
5
Rendering
Computer Grapics - CSL 1603
A Very Simple Solution
• First work out m and b:
5
3
2
7
2
5




m
5
4
2
5
3
2 



b
 Now for each x value work out the y value
5
3
2
5
4
3
5
3
)
3
( 



y 5
1
3
5
4
4
5
3
)
4
( 



y
5
4
3
5
4
5
5
3
)
5
( 



y 5
2
4
5
4
6
5
3
)
6
( 



y
Rendering
Computer Grapics - CSL 1603
A Very Simple Solution
• Now just round off the results and turn on these
pixels to draw our line
3
5
3
2
)
3
( 

y
3
5
1
3
)
4
( 

y
4
5
4
3
)
5
( 

y
4
5
2
4
)
6
( 

y
Rendering
Computer Grapics - CSL 1603
A Very Simple Solution
• However, this approach is just way too slow
• In particular,
• The equation y = mx + b requires the
multiplication of m by x
• Rounding off the resulting y coordinates
• We need a faster solution
Rendering
Computer Grapics - CSL 1603
A Quick Note About Slopes
• In the previous example, we chose to solve the
line equation to get y coordinate for each x
coordinate
• What if we had done it the other way around?
• So this gives us:
where: and
m
b
y
x


0
0
x
x
y
y
m
end
end


 0
0 x
m
y
b 


Rendering
Computer Grapics - CSL 1603
A Quick Note About Slopes
• Leaving out the details this gives us:
• We can see easily that this line doesn’t look very
good!
• We choose which way to work out the line pixels
based on the slope of the line
• If the slope of a line is between -1 and 1, work out y
coordinates based on x coordinates
• Otherwise do the opposite – x coordinates are computed
based on y coordinates
4
3
2
3
)
3
( 

x 5
3
1
5
)
4
( 

x
Rendering
Computer Grapics - CSL 1603
The DDAAlgorithm
• The digital differential analyzer (DDA)
algorithm takes an incremental approach in order
to speed up scan conversion
• Consider the list of points that we determined for
the line in our previous example:
(2, 2), (3, 23/5), (4, 31/5), (5, 34/5), (6, 42/5), (7, 5)
• Notice that as the x coordinates go up by one, the
y coordinates simply go up by the slope of the line
• This is the key insight in the DDA algorithm
Rendering
Computer Grapics - CSL 1603
The DDAAlgorithm
• When m is between -1 and 1, begin at the first
point in the line and, by incrementing x by 1,
calculate the corresponding y as follows
• When m is outside these limits, increment y by 1
and calculate the corresponding x as follows
m
y
y k
k 

1
m
x
x k
k
1
1 


Rendering
Computer Grapics - CSL 1603
The DDAAlgorithm
• Again the values calculated by the equations
used by the DDA algorithm must be rounded
Rendering
Computer Grapics - CSL 1603
The DDAAlgorithm Summary
• The DDA algorithm is much faster than our
previous attempt
• In particular, there are no longer any
multiplications involved
• However, there are still two big issues
• Accumulation of round-off errors can make the
pixelated line drift away from what was intended
• The rounding operations and floating point
arithmetic involved are time-consuming
Rendering
Computer Grapics - CSL 1603
The Bresenham Line Algorithm
• Move across the x axis in unit intervals and
at each step choose between two different y
coordinates
Rendering
Computer Grapics - CSL 1603
• The y coordinate on the mathematical line at
xk+1 is:
Derivation
• At sample position xk+1 the vertical
separations from the mathematical line are
labelled dupper and dlower
b
x
m
y k 

 )
1
(
Rendering
Computer Grapics - CSL 1603
Derivation
• So, dupper and dlower are given as follows:
and
• We can use these to make a simple decision
about which pixel is closer to the mathematical
line
k
lower y
y
d 

k
k y
b
x
m 


 )
1
(
y
y
d k
upper 

 )
1
(
b
x
m
y k
k 



 )
1
(
1
Rendering
Computer Grapics - CSL 1603
Derivation
•This simple decision is based on the difference
between the two pixel positions:
• Let’s substitute m with ∆y/∆x where ∆x and ∆y
are the differences between the end-points:
1
2
2
)
1
(
2 




 b
y
x
m
d
d k
k
upper
lower
)
1
2
2
)
1
(
2
(
)
( 








 b
y
x
x
y
x
d
d
x k
k
upper
lower
)
1
2
(
2
2
2 









 b
x
y
y
x
x
y k
k
c
y
x
x
y k
k 





 2
2
Rendering
Computer Grapics - CSL 1603
Derivation
• So, a decision parameter pk for the kth step
along a line is given by:
• The sign of the decision parameter pk is the
same as that of dlower – dupper
• If pk is negative, then choose the lower pixel,
otherwise choose the upper pixel
c
y
x
x
y
d
d
x
p
k
k
upper
lower
k










2
2
)
(
Rendering
Computer Grapics - CSL 1603
Derivation
• Remember coordinate changes occur along the x
axis in unit steps, so we can do everything with
integer calculations
• At step k+1 the decision parameter is given as:
•Subtracting pk from this we get:
c
y
x
x
y
p k
k
k 





 

 1
1
1 2
2
)
(
2
)
(
2 1
1
1 k
k
k
k
k
k y
y
x
x
x
y
p
p 





 


Rendering
Computer Grapics - CSL 1603
Derivation
• But, xk+1 is the same as xk+1 so:
•where yk+1 - yk is either 0 or 1 depending on the
sign of pk
• The first decision parameter p0, evaluated at
(x0, y0), is given as:
)
(
2
2 1
1 k
k
k
k y
y
x
y
p
p 




 

x
y
p 


 2
0
Rendering
Computer Grapics - CSL 1603
The Bresenham Line Algorithm
1. Input the two line end-points, storing the left end-point
in (x0, y0)
2. Plot the point (x0, y0)
3. Calculate the constants Δx, Δy, 2Δy, and (2Δy - 2Δx) and
get the first value for the decision parameter as:
4. At each xk along the line, starting at k = 0, perform the
following test. If p < 0, the next point to plot is
(xk+1, yk) and:
x
y
p 


 2
y
p
p 

 2
Rendering
Computer Grapics - CSL 1603
The Bresenham Line Algorithm
• The algorithm and derivation above assumes
slopes are less than 1 (|m| < 1.0), for other slopes
we need to adjust the algorithm slightly
Otherwise, the next point to plot is (xk+1, yk+1) and:
5. Repeat step 4 until x < (x2-1)
x
y
p
p 



 2
2
Rendering
Computer Grapics - CSL 1603
Circle Scan Conversion
• The equation for a circle is:
where r is the radius of the circle
• So, we can write a simple circle drawing
algorithm by solving the equation for y at unit x
intervals using:
2
2
2
r
y
x 

2
2
x
r
y 


Rendering
Computer Grapics - CSL 1603
Circle Scan Conversion
• Unsurprisingly this is not a brilliant solution
• Firstly, the resulting circle has large gaps where
the slope approaches the vertical
• Secondly, the calculations are not very efficient
• The square (multiply) operations
• The square root operation – try really hard to avoid
these!
• We need a more efficient, more accurate solution
Rendering
Computer Grapics - CSL 1603
Eight-Way Symmetry
• Circles centred at (0, 0) have eight-way symmetry
– this fact can be exploited to design an efficient
algorithm
Rendering
Computer Grapics - CSL 1603
Mid-Point Circle Algorithm
• An incremental algorithm for drawing circles
• Algorithm calculates pixels only for the top
right eighth of the circle
• Other points are derived using the eight-way
symmetry
Rendering
Computer Grapics - CSL 1603
Mid-Point Circle Algorithm
• Assume that we have
just plotted point (xk, yk)
•The next point is a
choice between (xk+1, yk)
and (xk+1, yk-1)
•We would like to choose
the point that is nearest to
the actual circle
• So how do we make this
choice?
Rendering
Computer Grapics - CSL 1603
Mid-Point Circle Algorithm
• Let’s re-jig the equation of the circle slightly to
give us:
• The equation evaluates as follows:
• By evaluating this function at the midpoint
between the candidate pixels we can make our
decision
2
2
2
)
,
( r
y
x
y
x
fcirc 










,
0
,
0
,
0
)
,
( y
x
f circ
boundary
circle
the
inside
is
y)
(x,
if
boundary
circle
on the
is
)
,
(
if y
x
boundary
circle
the
outside
is
)
,
(
if y
x
Rendering
Computer Grapics - CSL 1603
Mid-Point Circle Algorithm
• Assuming we have just plotted the pixel at (xk,yk) so
we need to choose between (xk+1,yk) and (xk+1,yk-1)
• Our decision variable can be defined as:
•If pk < 0 the midpoint is inside the circle and the pixel
at yk is closer to the circle
• Otherwise the midpoint is outside and yk-1 is closer
2
2
2
)
2
1
(
)
1
(
)
2
1
,
1
(
r
y
x
y
x
f
p
k
k
k
k
circ
k








Rendering
Computer Grapics - CSL 1603
Mid-Point Circle Algorithm
• To ensure things are as efficient as possible we
can do all of our calculations incrementally
• First consider:
or
where yk+1 is either yk or yk-1 depending on the
sign of pk
 
  2
2
1
2
1
1
1
2
1
]
1
)
1
[(
2
1
,
1
r
y
x
y
x
f
p
k
k
k
k
circ
k













1
)
(
)
(
)
1
(
2 1
2
2
1
1 






 

 k
k
k
k
k
k
k y
y
y
y
x
p
p
Rendering
Computer Grapics - CSL 1603
Mid-Point Circle Algorithm
• The first decision variable is given as
• Then if pk < 0 then the next decision variable is
given as:
• If pk > 0 then the decision variable is
r
r
r
r
f
p circ








4
5
)
2
1
(
1
)
2
1
,
1
(
2
2
0
1
2 1
1 

 
 k
k
k x
p
p
1
2
1
2 1
1 



 
 k
k
k
k y
x
p
p
Rendering
Computer Grapics - CSL 1603
Mid-Point Circle Algorithm
• Input radius r and circle centre (xc, yc), then set the
coordinates for the first point on the circumference
of a circle centred on the origin as:
• Calculate the initial value of the decision parameter
as:
• If p < 0, the next point along the circle centred on (0,
0) is (x+1, y) and:
))
roundoff(
,
0
(
)
,
( r
y
x 
r
p 

4
5
1
2 

 x
p
p
Rendering
Computer Grapics - CSL 1603
Mid-Point Circle Algorithm
• Otherwise the next point along the circle is
(x+1, y-1) and
• Determine symmetry points in the other seven
octants
• Move each calculated pixel position (x, y) onto
the circular path centred at (xc, yc) to plot the
coordinate values:
• Repeat steps 3 to 5 until x >= y
y
x
p
p 2
1
2 



c
x
x
x 
 c
y
y
y 

Rendering
Computer Grapics - CSL 1603
Thank You
Computer Grapics - CSL 1603

More Related Content

Similar to Lec-4_Rendering-1.pdf

Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsKetan Jani
 
2.circle
2.circle2.circle
2.circle
SakshiNailwal
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
Kamal Acharya
 
1536 graphics &amp; graphical programming
1536 graphics &amp; graphical  programming1536 graphics &amp; graphical  programming
1536 graphics &amp; graphical programming
Dr Fereidoun Dejahang
 
Computer graphics notes
Computer graphics notesComputer graphics notes
Computer graphics notes
RAJKIYA ENGINEERING COLLEGE, BANDA
 
CG-Lecture3.pptx
CG-Lecture3.pptxCG-Lecture3.pptx
CG-Lecture3.pptx
lakshitasarika2014
 
Rasterization.pptx
Rasterization.pptxRasterization.pptx
Rasterization.pptx
AhmadAbba6
 
Lecture 9-online
Lecture 9-onlineLecture 9-online
Lecture 9-online
lifebreath
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptx
Kokebe2
 
5_6221983039971394498.pptx
5_6221983039971394498.pptx5_6221983039971394498.pptx
5_6221983039971394498.pptx
NachiketKadlag1
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3Roziq Bahtiar
 
Unit 2
Unit 2Unit 2
Unit 2
ypnrao
 
mid point algorithm.pdf
mid point algorithm.pdfmid point algorithm.pdf
mid point algorithm.pdf
MehulMunshi3
 
Implementation
ImplementationImplementation
Implementation
Syed Zaid Irshad
 
Computer graphics notes watermark
Computer graphics notes watermarkComputer graphics notes watermark
Computer graphics notes watermark
RAJKIYA ENGINEERING COLLEGE, BANDA
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithmsMohammad Sadiq
 
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.pptLecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
KhondokarMdMehediHas
 
Unit 3
Unit 3Unit 3
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdfCD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
RajJain516913
 
02-gates-w.pptx
02-gates-w.pptx02-gates-w.pptx
02-gates-w.pptx
039JagadeeswaranS
 

Similar to Lec-4_Rendering-1.pdf (20)

Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
 
2.circle
2.circle2.circle
2.circle
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
1536 graphics &amp; graphical programming
1536 graphics &amp; graphical  programming1536 graphics &amp; graphical  programming
1536 graphics &amp; graphical programming
 
Computer graphics notes
Computer graphics notesComputer graphics notes
Computer graphics notes
 
CG-Lecture3.pptx
CG-Lecture3.pptxCG-Lecture3.pptx
CG-Lecture3.pptx
 
Rasterization.pptx
Rasterization.pptxRasterization.pptx
Rasterization.pptx
 
Lecture 9-online
Lecture 9-onlineLecture 9-online
Lecture 9-online
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptx
 
5_6221983039971394498.pptx
5_6221983039971394498.pptx5_6221983039971394498.pptx
5_6221983039971394498.pptx
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3
 
Unit 2
Unit 2Unit 2
Unit 2
 
mid point algorithm.pdf
mid point algorithm.pdfmid point algorithm.pdf
mid point algorithm.pdf
 
Implementation
ImplementationImplementation
Implementation
 
Computer graphics notes watermark
Computer graphics notes watermarkComputer graphics notes watermark
Computer graphics notes watermark
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.pptLecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
 
Unit 3
Unit 3Unit 3
Unit 3
 
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdfCD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
 
02-gates-w.pptx
02-gates-w.pptx02-gates-w.pptx
02-gates-w.pptx
 

Recently uploaded

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 

Recently uploaded (20)

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 

Lec-4_Rendering-1.pdf

  • 1. Rendering – 1 (Scan Conversion of Line and Circle) Lenin Laitonjam NIT Mizoram Computer Grapics - CSL 1603
  • 2. Rendering • To draw something on the screen, we need to consider pixel grid • Discreet space • We need to map the representations from continuous to discreet space • The mapping process is called rendering • Also called scan conversion/rasterization • We will have a look at scan conversion of • Point • Line • Circle Rendering Computer Grapics - CSL 1603
  • 3. Point Scan Conversion •Trivial: simply round off to the nearest pixel position The point can be mapped to any of the four pixel positions, depending on the coordinate value e.g. (1.1, 2.6) maps to (1, 3) Rendering Computer Grapics - CSL 1603
  • 4. Line Scan Conversion • A line segment is defined by the coordinate positions of the line end-points • What happens when we try to draw this on a pixel based display? • How to choose the correct pixels Rendering Computer Grapics - CSL 1603
  • 5. Line Equation • Slope-intercept line equation where x y y0 yend xend x0 b x m y    0 0 x x y y m end end    0 0 x m y b    Rendering Computer Grapics - CSL 1603
  • 6. A Very Simple Solution • Simply work out the corresponding y coordinate for each unit x coordinate • Let’s consider the following example x y (2, 2) (7, 5) 2 7 2 5 Rendering Computer Grapics - CSL 1603
  • 7. A Very Simple Solution • First work out m and b: 5 3 2 7 2 5     m 5 4 2 5 3 2     b  Now for each x value work out the y value 5 3 2 5 4 3 5 3 ) 3 (     y 5 1 3 5 4 4 5 3 ) 4 (     y 5 4 3 5 4 5 5 3 ) 5 (     y 5 2 4 5 4 6 5 3 ) 6 (     y Rendering Computer Grapics - CSL 1603
  • 8. A Very Simple Solution • Now just round off the results and turn on these pixels to draw our line 3 5 3 2 ) 3 (   y 3 5 1 3 ) 4 (   y 4 5 4 3 ) 5 (   y 4 5 2 4 ) 6 (   y Rendering Computer Grapics - CSL 1603
  • 9. A Very Simple Solution • However, this approach is just way too slow • In particular, • The equation y = mx + b requires the multiplication of m by x • Rounding off the resulting y coordinates • We need a faster solution Rendering Computer Grapics - CSL 1603
  • 10. A Quick Note About Slopes • In the previous example, we chose to solve the line equation to get y coordinate for each x coordinate • What if we had done it the other way around? • So this gives us: where: and m b y x   0 0 x x y y m end end    0 0 x m y b    Rendering Computer Grapics - CSL 1603
  • 11. A Quick Note About Slopes • Leaving out the details this gives us: • We can see easily that this line doesn’t look very good! • We choose which way to work out the line pixels based on the slope of the line • If the slope of a line is between -1 and 1, work out y coordinates based on x coordinates • Otherwise do the opposite – x coordinates are computed based on y coordinates 4 3 2 3 ) 3 (   x 5 3 1 5 ) 4 (   x Rendering Computer Grapics - CSL 1603
  • 12. The DDAAlgorithm • The digital differential analyzer (DDA) algorithm takes an incremental approach in order to speed up scan conversion • Consider the list of points that we determined for the line in our previous example: (2, 2), (3, 23/5), (4, 31/5), (5, 34/5), (6, 42/5), (7, 5) • Notice that as the x coordinates go up by one, the y coordinates simply go up by the slope of the line • This is the key insight in the DDA algorithm Rendering Computer Grapics - CSL 1603
  • 13. The DDAAlgorithm • When m is between -1 and 1, begin at the first point in the line and, by incrementing x by 1, calculate the corresponding y as follows • When m is outside these limits, increment y by 1 and calculate the corresponding x as follows m y y k k   1 m x x k k 1 1    Rendering Computer Grapics - CSL 1603
  • 14. The DDAAlgorithm • Again the values calculated by the equations used by the DDA algorithm must be rounded Rendering Computer Grapics - CSL 1603
  • 15. The DDAAlgorithm Summary • The DDA algorithm is much faster than our previous attempt • In particular, there are no longer any multiplications involved • However, there are still two big issues • Accumulation of round-off errors can make the pixelated line drift away from what was intended • The rounding operations and floating point arithmetic involved are time-consuming Rendering Computer Grapics - CSL 1603
  • 16. The Bresenham Line Algorithm • Move across the x axis in unit intervals and at each step choose between two different y coordinates Rendering Computer Grapics - CSL 1603
  • 17. • The y coordinate on the mathematical line at xk+1 is: Derivation • At sample position xk+1 the vertical separations from the mathematical line are labelled dupper and dlower b x m y k    ) 1 ( Rendering Computer Grapics - CSL 1603
  • 18. Derivation • So, dupper and dlower are given as follows: and • We can use these to make a simple decision about which pixel is closer to the mathematical line k lower y y d   k k y b x m     ) 1 ( y y d k upper    ) 1 ( b x m y k k      ) 1 ( 1 Rendering Computer Grapics - CSL 1603
  • 19. Derivation •This simple decision is based on the difference between the two pixel positions: • Let’s substitute m with ∆y/∆x where ∆x and ∆y are the differences between the end-points: 1 2 2 ) 1 ( 2       b y x m d d k k upper lower ) 1 2 2 ) 1 ( 2 ( ) (           b y x x y x d d x k k upper lower ) 1 2 ( 2 2 2            b x y y x x y k k c y x x y k k        2 2 Rendering Computer Grapics - CSL 1603
  • 20. Derivation • So, a decision parameter pk for the kth step along a line is given by: • The sign of the decision parameter pk is the same as that of dlower – dupper • If pk is negative, then choose the lower pixel, otherwise choose the upper pixel c y x x y d d x p k k upper lower k           2 2 ) ( Rendering Computer Grapics - CSL 1603
  • 21. Derivation • Remember coordinate changes occur along the x axis in unit steps, so we can do everything with integer calculations • At step k+1 the decision parameter is given as: •Subtracting pk from this we get: c y x x y p k k k           1 1 1 2 2 ) ( 2 ) ( 2 1 1 1 k k k k k k y y x x x y p p           Rendering Computer Grapics - CSL 1603
  • 22. Derivation • But, xk+1 is the same as xk+1 so: •where yk+1 - yk is either 0 or 1 depending on the sign of pk • The first decision parameter p0, evaluated at (x0, y0), is given as: ) ( 2 2 1 1 k k k k y y x y p p         x y p     2 0 Rendering Computer Grapics - CSL 1603
  • 23. The Bresenham Line Algorithm 1. Input the two line end-points, storing the left end-point in (x0, y0) 2. Plot the point (x0, y0) 3. Calculate the constants Δx, Δy, 2Δy, and (2Δy - 2Δx) and get the first value for the decision parameter as: 4. At each xk along the line, starting at k = 0, perform the following test. If p < 0, the next point to plot is (xk+1, yk) and: x y p     2 y p p    2 Rendering Computer Grapics - CSL 1603
  • 24. The Bresenham Line Algorithm • The algorithm and derivation above assumes slopes are less than 1 (|m| < 1.0), for other slopes we need to adjust the algorithm slightly Otherwise, the next point to plot is (xk+1, yk+1) and: 5. Repeat step 4 until x < (x2-1) x y p p      2 2 Rendering Computer Grapics - CSL 1603
  • 25. Circle Scan Conversion • The equation for a circle is: where r is the radius of the circle • So, we can write a simple circle drawing algorithm by solving the equation for y at unit x intervals using: 2 2 2 r y x   2 2 x r y    Rendering Computer Grapics - CSL 1603
  • 26. Circle Scan Conversion • Unsurprisingly this is not a brilliant solution • Firstly, the resulting circle has large gaps where the slope approaches the vertical • Secondly, the calculations are not very efficient • The square (multiply) operations • The square root operation – try really hard to avoid these! • We need a more efficient, more accurate solution Rendering Computer Grapics - CSL 1603
  • 27. Eight-Way Symmetry • Circles centred at (0, 0) have eight-way symmetry – this fact can be exploited to design an efficient algorithm Rendering Computer Grapics - CSL 1603
  • 28. Mid-Point Circle Algorithm • An incremental algorithm for drawing circles • Algorithm calculates pixels only for the top right eighth of the circle • Other points are derived using the eight-way symmetry Rendering Computer Grapics - CSL 1603
  • 29. Mid-Point Circle Algorithm • Assume that we have just plotted point (xk, yk) •The next point is a choice between (xk+1, yk) and (xk+1, yk-1) •We would like to choose the point that is nearest to the actual circle • So how do we make this choice? Rendering Computer Grapics - CSL 1603
  • 30. Mid-Point Circle Algorithm • Let’s re-jig the equation of the circle slightly to give us: • The equation evaluates as follows: • By evaluating this function at the midpoint between the candidate pixels we can make our decision 2 2 2 ) , ( r y x y x fcirc            , 0 , 0 , 0 ) , ( y x f circ boundary circle the inside is y) (x, if boundary circle on the is ) , ( if y x boundary circle the outside is ) , ( if y x Rendering Computer Grapics - CSL 1603
  • 31. Mid-Point Circle Algorithm • Assuming we have just plotted the pixel at (xk,yk) so we need to choose between (xk+1,yk) and (xk+1,yk-1) • Our decision variable can be defined as: •If pk < 0 the midpoint is inside the circle and the pixel at yk is closer to the circle • Otherwise the midpoint is outside and yk-1 is closer 2 2 2 ) 2 1 ( ) 1 ( ) 2 1 , 1 ( r y x y x f p k k k k circ k         Rendering Computer Grapics - CSL 1603
  • 32. Mid-Point Circle Algorithm • To ensure things are as efficient as possible we can do all of our calculations incrementally • First consider: or where yk+1 is either yk or yk-1 depending on the sign of pk     2 2 1 2 1 1 1 2 1 ] 1 ) 1 [( 2 1 , 1 r y x y x f p k k k k circ k              1 ) ( ) ( ) 1 ( 2 1 2 2 1 1            k k k k k k k y y y y x p p Rendering Computer Grapics - CSL 1603
  • 33. Mid-Point Circle Algorithm • The first decision variable is given as • Then if pk < 0 then the next decision variable is given as: • If pk > 0 then the decision variable is r r r r f p circ         4 5 ) 2 1 ( 1 ) 2 1 , 1 ( 2 2 0 1 2 1 1      k k k x p p 1 2 1 2 1 1        k k k k y x p p Rendering Computer Grapics - CSL 1603
  • 34. Mid-Point Circle Algorithm • Input radius r and circle centre (xc, yc), then set the coordinates for the first point on the circumference of a circle centred on the origin as: • Calculate the initial value of the decision parameter as: • If p < 0, the next point along the circle centred on (0, 0) is (x+1, y) and: )) roundoff( , 0 ( ) , ( r y x  r p   4 5 1 2    x p p Rendering Computer Grapics - CSL 1603
  • 35. Mid-Point Circle Algorithm • Otherwise the next point along the circle is (x+1, y-1) and • Determine symmetry points in the other seven octants • Move each calculated pixel position (x, y) onto the circular path centred at (xc, yc) to plot the coordinate values: • Repeat steps 3 to 5 until x >= y y x p p 2 1 2     c x x x   c y y y   Rendering Computer Grapics - CSL 1603