SlideShare una empresa de Scribd logo
1 de 36
159.235 Graphics 1
159.235 Graphics & Graphical
Programming
Lecture 14 - Lines & Circles
159.235 Graphics 2
Towards the Ideal Line
• We can only do a discrete approximation
• Illuminate pixels as close to the true path as
possible, consider bi-level display only
– Pixels are either lit or not lit
159.235 Graphics 3
What is an ideal line
• Must appear straight and continuous
– Only possible axis-aligned and 45o
lines
• Must interpolate both defining end points
• Must have uniform density and intensity
– Consistent within a line and over all lines
– What about antialiasing?
• Must be efficient, drawn quickly
– Lots of them are required!!!
159.235 Graphics 4
Simple Line
Based on slope-intercept
algorithm from algebra:
y = mx + b
Simple approach:
increment x, solve for y
Floating point arithmetic
required
159.235 Graphics 5
Does it Work?
It seems to work okay for lines with
a slope of 1 or less,
but doesn’t work well for lines with
slope greater than 1 – lines become
more discontinuous in appearance
and we must add more than 1 pixel
per column to make it work.
Solution? - use symmetry.
159.235 Graphics 6
Modify algorithm per octant
OR, increment along x-axis if dy<dx else increment along y-axis
159.235 Graphics 7
DDA algorithm
• DDA = Digital Differential Analyser
– finite differences
• Treat line as parametric equation in t :
)()(
)()(
121
121
yytyty
xxtxtx
−+=
−+=
),(
),(
22
11
yx
yxStart point -
End point -
159.235 Graphics 8
DDA Algorithm
• Start at t = 0
• At each step, increment t by dt
• Choose appropriate value for dt
• Ensure no pixels are missed:
– Implies: and
• Set dt to maximum of dx and dy
)()(
)()(
121
121
yytyty
xxtxtx
−+=
−+=
dt
dy
yy
dt
dx
xx
oldnew
oldnew
+=
+=
1<
dt
dx
1<
dt
dy
159.235 Graphics 9
DDA algorithm
line(int x1, int y1, int x2, int y2)
{
float x,y;
int dx = x2-x1, dy = y2-y1;
int n = max(abs(dx),abs(dy));
float dt = n, dxdt = dx/dt, dydt = dy/dt;
x = x1;
y = y1;
while( n-- ) {
point(round(x),round(y));
x += dxdt;
y += dydt;
}
}
n - range of t.
159.235 Graphics 10
DDA algorithm
• Still need a lot of floating point arithmetic.
– 2 ‘round’s and 2 adds per pixel.
• Is there a simpler way ?
• Can we use only integer arithmetic ?
– Easier to implement in hardware.
159.235 Graphics 11
Observation on lines.
while( n-- )
{
draw(x,y);
move right;
if( below line )
move up;
}
159.235 Graphics 12
Testing for the side of a line.
• Need a test to determine which side of a line a
pixel lies.
• Write the line in implicit form:
0),( =++= cbyaxyxF
• Easy to prove F<0 for points above the line,
F>0 for points below.
159.235 Graphics 13
Testing for the side of a line.
• Need to find coefficients a,b,c.
• Recall explicit, slope-intercept form :
• So:
0),( =++= cbyaxyxF
bx
dx
dy
ybmxy +=+= soand
0..),( =+−= cydxxdyyxF
159.235 Graphics 14
Decision variable.
Previous
Pixel
(xp,yp)
Choices for
Current pixel
Choices for
Next pixel
Evaluate F at point M
Referred to as decision variable
)
2
1
,1( ++= pp yxFd
M
NE
E
159.235 Graphics 15
Decision variable.
Evaluate d for next pixel, Depends on whether E or NE Is chosen :
If E chosen :
cybxayxFd ppppnew ++++=++= )
2
1
()2()
2
1
,2(
But recall :
cybxa
yxFd
pp
ppold
++++=
++=
)
2
1
()1(
)
2
1
,1(
So :
dyd
add
old
oldnew
+=
+=
M
E
NE
Previous
Pixel
(xp,yp)
Choices for
Current pixel
Choices for
Next pixel
159.235 Graphics 16
Decision variable.
If NE was chosen :
cybxayxFd ppppnew ++++=++= )
2
3
()2()
2
3
,2(
So :
dxdyd
badd
old
oldnew
−+=
++=
M
E
NE
Previous
Pixel
(xp,yp)
Choices for
Current pixel
Choices for
Next pixel
159.235 Graphics 17
Summary of mid-point algorithm
• Choose between 2 pixels at each step based
upon sign of decision variable.
• Update decision variable based upon which
pixel is chosen.
• Start point is simply first endpoint (x1,y1).
• Need to calculate initial value for d
159.235 Graphics 18
Initial value of d.
2
)
2
1
()1()
2
1
,1(
11
1111
b
acbyax
cybxayxFdstart
++++=
++++=++=
But (x1,y1) is a point on the line, so F(x1,y1) =0
2/dxdydstart −=
Conventional to multiply by 2 to remove fraction ⇒ doesn’t effect sign.
2
),( 11
b
ayxF ++=
Start point is (x1,y1)
159.235 Graphics 19
Bresenham algorithm
void MidpointLine(int
x1,y1,x2,y2)
{
int dx=x2-x1;
int dy=y2-y1;
int d=2*dy-dx;
int increE=2*dy;
int incrNE=2*(dy-dx);
x=x1;
y=y1;
WritePixel(x,y);
while (x < x2) {
if (d<= 0) {
d+=incrE;
x++
} else {
d+=incrNE;
x++;
y++;
}
WritePixel(x,y);
}
}
159.235 Graphics 20
Bresenham was not the end!
2-step algorithm by Xiaolin Wu:
(see Graphics Gems 1, by Brian Wyvill)
Treat line drawing as an automaton , or finite
state machine, ie. looking at next two pixels of a
line, easy to see that only a finite set of
possibilities exist.
The 2-step algorithm exploits symmetry by
simultaneously drawing from both ends towards
the midpoint.
159.235 Graphics 21
Two-step Algorithm
Possible positions of next two pixels dependent on slope –
current pixel in blue:
Slope between 0 and ½
Slope between ½ and 1
Slope between 1 and 2
Slope greater than 2
159.235 Graphics 22
Circle drawing.
• Can also use Bresenham to draw circles.
• Use 8-fold symmetry
Choices for
Next pixel
M
E
SE
Previous
Pixel
Choices for
Current pixel
159.235 Graphics 23
Circle drawing.
• Implicit form for a circle is:
2 2 2
) ( ) ( ) , (r y y x x y x fc c− − + − =
)32(chosenisEIf
)522(chosenisSEIf
++=
+−+=
poldnew
ppoldnew
xdd
yxdd
• Functions are linear equations in terms of (xp,yp)
–Termed point of evaluation
159.235 Graphics 24
Problems with Bresenham algorithm
• Pixels are drawn as a single line ⇒ unequal
line intensity with change in angle.
Pixel density = n pixels/mm
Pixel density = √2.n pixels/mm
Can draw lines in darker colours
according to line direction.
- Better solution : antialiasing !
159.235 Graphics 25
Summary of line drawing so far.
• Explicit form of line
– Inefficient, difficult to control.
• Parametric form of line.
– Express line in terms of parameter t
– DDA algorithm
• Implicit form of line
– Only need to test for ‘side’ of line.
– Bresenham algorithm.
– Can also draw circles.
159.235 Graphics 26
• Sampling theory tells us aliasing is caused by frequencies being present
above the Nyquist limit.
• Ideal solution : band-pass filter to remove high frequencies.
• Fourier transform tells us the transform of a band-pass filter is a sinc function.
• Convolution theory tells us we can convolve with a sinc function in the
spatial domain instead.
• A sinc function is an impractical filter.
Summary of aliasing.
159.235 Graphics 27
Antialiasing
Gather all the values into
the pixels
-Loop round the pixels.
-Used for complex scenes.
-Cast out rays, convolve result
into pixel
(Pixel Grid ⊗ Impulse) x line
• Two ways of antialiasing
159.235 Graphics 28
Antialiasing
• Two ways of antialiasing
Scatter values into the
pixels
-Loop along the line.
-If line is delta function, we just
sweep the pixel filter along the
line
(Line ⊗ Pixel) x impulse
159.235 Graphics 29
Antialiasing lines.
• Obvious : Need a grey level display in order to remove aliasing.
• Convolve line with filter function for pixel
– Box filter ⇒area sample
– Convolution with conical filter function.
• Price to be paid : trade off spatial resolution
– Line appears more ‘blurred’, it’s exact position is no longer as well defined.
– In practice : contrast of lines much reduced.
1 pixel
159.235 Graphics 30
Antialiasing by area sampling.
• Convolve line with box filter function
∀ ⇒ Draw line as thin rectangle.
• Calculate area of square pixel covered by line
Problem :
• Equal areas contribute equal intensity,
regardless of distance from line centre
• Small area in the pixels centre
contributes as much as a small area at the
pixels edge.
159.235 Graphics 31
Weighted area filtering.
• Convolution with a conical filter.
• Easy to compute, symmetrical.
Lines are same distance
from pixel centre, but
area of pixel covered is
very different in the square case
159.235 Graphics 32
Weighted area filtering.
• Diameter is 2 pixels, so overlap occurs
– Ensures all of the grid is covered
• Area is normalised
• Only need to know distance from pixel
centre to line
• Gupta-Sproull algorithm.
159.235 Graphics 33
Gupta-Sproull algorithm.
M
NE
Calculate distance using features of mid-point algorithm
D
Angle = ∅v
dy
dx
22
cos
dydx
vdx
vD
+
=
= φ
E
159.235 Graphics 34
Gupta-Sproull algorithm.
Calculate distance using features of mid-point algorithm
22
cos
dydx
vdx
vD
+
=
= φ
22
2 dydx
dxd
D
+
+
=
See Foley Van-Dam
Sec. 3.17
d is the decision variable.
159.235 Graphics 35
Filter shape.
• Cone filter
– Simply set pixel to a multiple of the distance
• Gaussian filter
– Store precomputed values in look up table
• Thick lines
– Store area intersection in look-up table.
159.235 Graphics 36
Summary of antialiasing lines
• Use square unweighted average filter
– Poor representation of line.
• Weighted average filter better
• Use Cone
– Symmetrical, only need to know distance
– Use decision variable calculated in Bresenham.
– Gupta-Sproull algorithm.

Más contenido relacionado

La actualidad más candente

Game development terminologies
Game development terminologiesGame development terminologies
Game development terminologiesAhmed Badr
 
Computer Graphics Notes
Computer Graphics NotesComputer Graphics Notes
Computer Graphics NotesGurpreet singh
 
Introduction to computer graphics
Introduction to computer graphics Introduction to computer graphics
Introduction to computer graphics Priyodarshini Dhar
 
Multimedia graphics and image data representation
Multimedia graphics and image data representationMultimedia graphics and image data representation
Multimedia graphics and image data representationMazin Alwaaly
 
Image processing spatialfiltering
Image processing spatialfilteringImage processing spatialfiltering
Image processing spatialfilteringJohn Williams
 
Numerical unit 1
Numerical unit 1Numerical unit 1
Numerical unit 1Ankit Garg
 
Lecture5 graphics
Lecture5   graphicsLecture5   graphics
Lecture5 graphicsMr SMAK
 
Digital image processing &amp; computer graphics
Digital image processing &amp; computer graphicsDigital image processing &amp; computer graphics
Digital image processing &amp; computer graphicsAnkit Garg
 
04 image enhancement edge detection
04 image enhancement edge detection04 image enhancement edge detection
04 image enhancement edge detectionRumah Belajar
 
Animation Techniques
Animation TechniquesAnimation Techniques
Animation TechniquesMahith
 
Image Interpolation Techniques with Optical and Digital Zoom Concepts
Image Interpolation Techniques with Optical and Digital Zoom ConceptsImage Interpolation Techniques with Optical and Digital Zoom Concepts
Image Interpolation Techniques with Optical and Digital Zoom Conceptsmmjalbiaty
 

La actualidad más candente (20)

Animation
AnimationAnimation
Animation
 
Game development terminologies
Game development terminologiesGame development terminologies
Game development terminologies
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
Computer Graphics Notes
Computer Graphics NotesComputer Graphics Notes
Computer Graphics Notes
 
Introduction to computer graphics
Introduction to computer graphics Introduction to computer graphics
Introduction to computer graphics
 
Multimedia graphics and image data representation
Multimedia graphics and image data representationMultimedia graphics and image data representation
Multimedia graphics and image data representation
 
COM2304: Color and Color Models
COM2304: Color and Color ModelsCOM2304: Color and Color Models
COM2304: Color and Color Models
 
Image processing spatialfiltering
Image processing spatialfilteringImage processing spatialfiltering
Image processing spatialfiltering
 
2.spatial filtering
2.spatial filtering2.spatial filtering
2.spatial filtering
 
Ch06
Ch06Ch06
Ch06
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Numerical unit 1
Numerical unit 1Numerical unit 1
Numerical unit 1
 
Computer graphics notes
Computer graphics notesComputer graphics notes
Computer graphics notes
 
Lecture5 graphics
Lecture5   graphicsLecture5   graphics
Lecture5 graphics
 
Digital image processing &amp; computer graphics
Digital image processing &amp; computer graphicsDigital image processing &amp; computer graphics
Digital image processing &amp; computer graphics
 
04 image enhancement edge detection
04 image enhancement edge detection04 image enhancement edge detection
04 image enhancement edge detection
 
Animation Techniques
Animation TechniquesAnimation Techniques
Animation Techniques
 
Image Interpolation Techniques with Optical and Digital Zoom Concepts
Image Interpolation Techniques with Optical and Digital Zoom ConceptsImage Interpolation Techniques with Optical and Digital Zoom Concepts
Image Interpolation Techniques with Optical and Digital Zoom Concepts
 
Image compression
Image compressionImage compression
Image compression
 
Clipping 22
Clipping 22Clipping 22
Clipping 22
 

Destacado

Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4Roziq Bahtiar
 
Lab lecture 2 bresenham
Lab lecture 2 bresenhamLab lecture 2 bresenham
Lab lecture 2 bresenhamsimpleok
 
CG OpenGL line & area-course 3
CG OpenGL line & area-course 3CG OpenGL line & area-course 3
CG OpenGL line & area-course 3fungfung Chen
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsKetan Jani
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationMuhammad Fiaz
 
Computer graphics presentation
Computer graphics presentationComputer graphics presentation
Computer graphics presentationLOKENDRA PRAJAPATI
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithmsMohammad Sadiq
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer GraphicsAdri Jovin
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALVivek Kumar Sinha
 
Computer Graphics Unit 1 - Introduction(RGPV syllabus)
Computer Graphics Unit 1 - Introduction(RGPV syllabus)Computer Graphics Unit 1 - Introduction(RGPV syllabus)
Computer Graphics Unit 1 - Introduction(RGPV syllabus)NANDINI SHARMA
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmMahesh Kodituwakku
 
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Saikrishna Tanguturu
 

Destacado (17)

Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4
 
Lab lecture 2 bresenham
Lab lecture 2 bresenhamLab lecture 2 bresenham
Lab lecture 2 bresenham
 
Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)
 
Lect3cg2011
Lect3cg2011Lect3cg2011
Lect3cg2011
 
Lect14 lines+circles
Lect14 lines+circlesLect14 lines+circles
Lect14 lines+circles
 
CG OpenGL line & area-course 3
CG OpenGL line & area-course 3CG OpenGL line & area-course 3
CG OpenGL line & area-course 3
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
 
bresenham circles and polygons in computer graphics(Computer graphics tutorials)
bresenham circles and polygons in computer graphics(Computer graphics tutorials)bresenham circles and polygons in computer graphics(Computer graphics tutorials)
bresenham circles and polygons in computer graphics(Computer graphics tutorials)
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Computer graphics presentation
Computer graphics presentationComputer graphics presentation
Computer graphics presentation
 
Unit 3
Unit 3Unit 3
Unit 3
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
 
Computer Graphics Unit 1 - Introduction(RGPV syllabus)
Computer Graphics Unit 1 - Introduction(RGPV syllabus)Computer Graphics Unit 1 - Introduction(RGPV syllabus)
Computer Graphics Unit 1 - Introduction(RGPV syllabus)
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
 
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
 

Similar a Drawing Lines and Circles in Graphics

Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygonsaa11bb11
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons dericationKumar
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1aravindangc
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterizationMaaz Rizwan
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterizationMaaz Rizwan
 
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohichapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi54MahakBansal
 
Line drawing Algorithm DDA in computer Graphics.pdf
Line drawing Algorithm DDA in computer Graphics.pdfLine drawing Algorithm DDA in computer Graphics.pdf
Line drawing Algorithm DDA in computer Graphics.pdfRAJARATNAS
 
Unit 2
Unit 2Unit 2
Unit 2ypnrao
 
ImageSegmentation (1).ppt
ImageSegmentation (1).pptImageSegmentation (1).ppt
ImageSegmentation (1).pptNoorUlHaq47
 
ImageSegmentation.ppt
ImageSegmentation.pptImageSegmentation.ppt
ImageSegmentation.pptAVUDAI1
 
ImageSegmentation.ppt
ImageSegmentation.pptImageSegmentation.ppt
ImageSegmentation.pptDEEPUKUMARR
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer GraphicsKamal Acharya
 
Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm
Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm
Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm Aparna Joshi
 
4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptxssuser255bf1
 
Lline Drawing Algorithm
Lline Drawing AlgorithmLline Drawing Algorithm
Lline Drawing Algorithmnehrurevathy
 

Similar a Drawing Lines and Circles in Graphics (20)

Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterization
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterization
 
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohichapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
 
Lec-4_Rendering-1.pdf
Lec-4_Rendering-1.pdfLec-4_Rendering-1.pdf
Lec-4_Rendering-1.pdf
 
Line drawing Algorithm DDA in computer Graphics.pdf
Line drawing Algorithm DDA in computer Graphics.pdfLine drawing Algorithm DDA in computer Graphics.pdf
Line drawing Algorithm DDA in computer Graphics.pdf
 
Unit 2
Unit 2Unit 2
Unit 2
 
ImageSegmentation (1).ppt
ImageSegmentation (1).pptImageSegmentation (1).ppt
ImageSegmentation (1).ppt
 
ImageSegmentation.ppt
ImageSegmentation.pptImageSegmentation.ppt
ImageSegmentation.ppt
 
ImageSegmentation.ppt
ImageSegmentation.pptImageSegmentation.ppt
ImageSegmentation.ppt
 
03.Scan Conversion.ppt
03.Scan Conversion.ppt03.Scan Conversion.ppt
03.Scan Conversion.ppt
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm
Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm
Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm
 
Image segmentation
Image segmentationImage segmentation
Image segmentation
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx
 
Computer graphics 2
Computer graphics 2Computer graphics 2
Computer graphics 2
 
Lline Drawing Algorithm
Lline Drawing AlgorithmLline Drawing Algorithm
Lline Drawing Algorithm
 

Más de Dr Fereidoun Dejahang

27 j20 my news punch -dr f dejahang 27-01-2020
27 j20 my news punch -dr f dejahang  27-01-202027 j20 my news punch -dr f dejahang  27-01-2020
27 j20 my news punch -dr f dejahang 27-01-2020Dr Fereidoun Dejahang
 
028 fast-tracking projects &amp; cost overrun
028 fast-tracking projects &amp; cost overrun028 fast-tracking projects &amp; cost overrun
028 fast-tracking projects &amp; cost overrunDr Fereidoun Dejahang
 
026 fast react-productivity improvement
026 fast react-productivity improvement026 fast react-productivity improvement
026 fast react-productivity improvementDr Fereidoun Dejahang
 
022 b construction productivity-write
022 b construction productivity-write022 b construction productivity-write
022 b construction productivity-writeDr Fereidoun Dejahang
 
016 communication in construction sector
016 communication in construction sector016 communication in construction sector
016 communication in construction sectorDr Fereidoun Dejahang
 
014 changes-cost overrun measurement
014 changes-cost overrun measurement014 changes-cost overrun measurement
014 changes-cost overrun measurementDr Fereidoun Dejahang
 
013 changes in construction projects
013 changes in construction projects013 changes in construction projects
013 changes in construction projectsDr Fereidoun Dejahang
 

Más de Dr Fereidoun Dejahang (20)

27 j20 my news punch -dr f dejahang 27-01-2020
27 j20 my news punch -dr f dejahang  27-01-202027 j20 my news punch -dr f dejahang  27-01-2020
27 j20 my news punch -dr f dejahang 27-01-2020
 
28 dej my news punch rev 28-12-2019
28 dej my news punch rev 28-12-201928 dej my news punch rev 28-12-2019
28 dej my news punch rev 28-12-2019
 
16 fd my news punch rev 16-12-2019
16 fd my news punch rev 16-12-201916 fd my news punch rev 16-12-2019
16 fd my news punch rev 16-12-2019
 
029 fast-tracking projects
029 fast-tracking projects029 fast-tracking projects
029 fast-tracking projects
 
028 fast-tracking projects &amp; cost overrun
028 fast-tracking projects &amp; cost overrun028 fast-tracking projects &amp; cost overrun
028 fast-tracking projects &amp; cost overrun
 
027 fast-tracked projects-materials
027 fast-tracked projects-materials027 fast-tracked projects-materials
027 fast-tracked projects-materials
 
026 fast react-productivity improvement
026 fast react-productivity improvement026 fast react-productivity improvement
026 fast react-productivity improvement
 
025 enterprise resources management
025 enterprise resources management025 enterprise resources management
025 enterprise resources management
 
022 b construction productivity-write
022 b construction productivity-write022 b construction productivity-write
022 b construction productivity-write
 
022 a construction productivity (2)
022 a construction productivity (2)022 a construction productivity (2)
022 a construction productivity (2)
 
021 construction productivity (1)
021 construction productivity (1)021 construction productivity (1)
021 construction productivity (1)
 
019 competencies-managers
019 competencies-managers019 competencies-managers
019 competencies-managers
 
018 company productivity
018 company productivity018 company productivity
018 company productivity
 
017 communication
017 communication017 communication
017 communication
 
016 communication in construction sector
016 communication in construction sector016 communication in construction sector
016 communication in construction sector
 
015 changes-process model
015 changes-process model015 changes-process model
015 changes-process model
 
014 changes-cost overrun measurement
014 changes-cost overrun measurement014 changes-cost overrun measurement
014 changes-cost overrun measurement
 
013 changes in construction projects
013 changes in construction projects013 changes in construction projects
013 changes in construction projects
 
012 bussiness planning process
012 bussiness planning process012 bussiness planning process
012 bussiness planning process
 
011 business performance management
011 business performance management011 business performance management
011 business performance management
 

Último

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Último (20)

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 

Drawing Lines and Circles in Graphics

  • 1. 159.235 Graphics 1 159.235 Graphics & Graphical Programming Lecture 14 - Lines & Circles
  • 2. 159.235 Graphics 2 Towards the Ideal Line • We can only do a discrete approximation • Illuminate pixels as close to the true path as possible, consider bi-level display only – Pixels are either lit or not lit
  • 3. 159.235 Graphics 3 What is an ideal line • Must appear straight and continuous – Only possible axis-aligned and 45o lines • Must interpolate both defining end points • Must have uniform density and intensity – Consistent within a line and over all lines – What about antialiasing? • Must be efficient, drawn quickly – Lots of them are required!!!
  • 4. 159.235 Graphics 4 Simple Line Based on slope-intercept algorithm from algebra: y = mx + b Simple approach: increment x, solve for y Floating point arithmetic required
  • 5. 159.235 Graphics 5 Does it Work? It seems to work okay for lines with a slope of 1 or less, but doesn’t work well for lines with slope greater than 1 – lines become more discontinuous in appearance and we must add more than 1 pixel per column to make it work. Solution? - use symmetry.
  • 6. 159.235 Graphics 6 Modify algorithm per octant OR, increment along x-axis if dy<dx else increment along y-axis
  • 7. 159.235 Graphics 7 DDA algorithm • DDA = Digital Differential Analyser – finite differences • Treat line as parametric equation in t : )()( )()( 121 121 yytyty xxtxtx −+= −+= ),( ),( 22 11 yx yxStart point - End point -
  • 8. 159.235 Graphics 8 DDA Algorithm • Start at t = 0 • At each step, increment t by dt • Choose appropriate value for dt • Ensure no pixels are missed: – Implies: and • Set dt to maximum of dx and dy )()( )()( 121 121 yytyty xxtxtx −+= −+= dt dy yy dt dx xx oldnew oldnew += += 1< dt dx 1< dt dy
  • 9. 159.235 Graphics 9 DDA algorithm line(int x1, int y1, int x2, int y2) { float x,y; int dx = x2-x1, dy = y2-y1; int n = max(abs(dx),abs(dy)); float dt = n, dxdt = dx/dt, dydt = dy/dt; x = x1; y = y1; while( n-- ) { point(round(x),round(y)); x += dxdt; y += dydt; } } n - range of t.
  • 10. 159.235 Graphics 10 DDA algorithm • Still need a lot of floating point arithmetic. – 2 ‘round’s and 2 adds per pixel. • Is there a simpler way ? • Can we use only integer arithmetic ? – Easier to implement in hardware.
  • 11. 159.235 Graphics 11 Observation on lines. while( n-- ) { draw(x,y); move right; if( below line ) move up; }
  • 12. 159.235 Graphics 12 Testing for the side of a line. • Need a test to determine which side of a line a pixel lies. • Write the line in implicit form: 0),( =++= cbyaxyxF • Easy to prove F<0 for points above the line, F>0 for points below.
  • 13. 159.235 Graphics 13 Testing for the side of a line. • Need to find coefficients a,b,c. • Recall explicit, slope-intercept form : • So: 0),( =++= cbyaxyxF bx dx dy ybmxy +=+= soand 0..),( =+−= cydxxdyyxF
  • 14. 159.235 Graphics 14 Decision variable. Previous Pixel (xp,yp) Choices for Current pixel Choices for Next pixel Evaluate F at point M Referred to as decision variable ) 2 1 ,1( ++= pp yxFd M NE E
  • 15. 159.235 Graphics 15 Decision variable. Evaluate d for next pixel, Depends on whether E or NE Is chosen : If E chosen : cybxayxFd ppppnew ++++=++= ) 2 1 ()2() 2 1 ,2( But recall : cybxa yxFd pp ppold ++++= ++= ) 2 1 ()1( ) 2 1 ,1( So : dyd add old oldnew += += M E NE Previous Pixel (xp,yp) Choices for Current pixel Choices for Next pixel
  • 16. 159.235 Graphics 16 Decision variable. If NE was chosen : cybxayxFd ppppnew ++++=++= ) 2 3 ()2() 2 3 ,2( So : dxdyd badd old oldnew −+= ++= M E NE Previous Pixel (xp,yp) Choices for Current pixel Choices for Next pixel
  • 17. 159.235 Graphics 17 Summary of mid-point algorithm • Choose between 2 pixels at each step based upon sign of decision variable. • Update decision variable based upon which pixel is chosen. • Start point is simply first endpoint (x1,y1). • Need to calculate initial value for d
  • 18. 159.235 Graphics 18 Initial value of d. 2 ) 2 1 ()1() 2 1 ,1( 11 1111 b acbyax cybxayxFdstart ++++= ++++=++= But (x1,y1) is a point on the line, so F(x1,y1) =0 2/dxdydstart −= Conventional to multiply by 2 to remove fraction ⇒ doesn’t effect sign. 2 ),( 11 b ayxF ++= Start point is (x1,y1)
  • 19. 159.235 Graphics 19 Bresenham algorithm void MidpointLine(int x1,y1,x2,y2) { int dx=x2-x1; int dy=y2-y1; int d=2*dy-dx; int increE=2*dy; int incrNE=2*(dy-dx); x=x1; y=y1; WritePixel(x,y); while (x < x2) { if (d<= 0) { d+=incrE; x++ } else { d+=incrNE; x++; y++; } WritePixel(x,y); } }
  • 20. 159.235 Graphics 20 Bresenham was not the end! 2-step algorithm by Xiaolin Wu: (see Graphics Gems 1, by Brian Wyvill) Treat line drawing as an automaton , or finite state machine, ie. looking at next two pixels of a line, easy to see that only a finite set of possibilities exist. The 2-step algorithm exploits symmetry by simultaneously drawing from both ends towards the midpoint.
  • 21. 159.235 Graphics 21 Two-step Algorithm Possible positions of next two pixels dependent on slope – current pixel in blue: Slope between 0 and ½ Slope between ½ and 1 Slope between 1 and 2 Slope greater than 2
  • 22. 159.235 Graphics 22 Circle drawing. • Can also use Bresenham to draw circles. • Use 8-fold symmetry Choices for Next pixel M E SE Previous Pixel Choices for Current pixel
  • 23. 159.235 Graphics 23 Circle drawing. • Implicit form for a circle is: 2 2 2 ) ( ) ( ) , (r y y x x y x fc c− − + − = )32(chosenisEIf )522(chosenisSEIf ++= +−+= poldnew ppoldnew xdd yxdd • Functions are linear equations in terms of (xp,yp) –Termed point of evaluation
  • 24. 159.235 Graphics 24 Problems with Bresenham algorithm • Pixels are drawn as a single line ⇒ unequal line intensity with change in angle. Pixel density = n pixels/mm Pixel density = √2.n pixels/mm Can draw lines in darker colours according to line direction. - Better solution : antialiasing !
  • 25. 159.235 Graphics 25 Summary of line drawing so far. • Explicit form of line – Inefficient, difficult to control. • Parametric form of line. – Express line in terms of parameter t – DDA algorithm • Implicit form of line – Only need to test for ‘side’ of line. – Bresenham algorithm. – Can also draw circles.
  • 26. 159.235 Graphics 26 • Sampling theory tells us aliasing is caused by frequencies being present above the Nyquist limit. • Ideal solution : band-pass filter to remove high frequencies. • Fourier transform tells us the transform of a band-pass filter is a sinc function. • Convolution theory tells us we can convolve with a sinc function in the spatial domain instead. • A sinc function is an impractical filter. Summary of aliasing.
  • 27. 159.235 Graphics 27 Antialiasing Gather all the values into the pixels -Loop round the pixels. -Used for complex scenes. -Cast out rays, convolve result into pixel (Pixel Grid ⊗ Impulse) x line • Two ways of antialiasing
  • 28. 159.235 Graphics 28 Antialiasing • Two ways of antialiasing Scatter values into the pixels -Loop along the line. -If line is delta function, we just sweep the pixel filter along the line (Line ⊗ Pixel) x impulse
  • 29. 159.235 Graphics 29 Antialiasing lines. • Obvious : Need a grey level display in order to remove aliasing. • Convolve line with filter function for pixel – Box filter ⇒area sample – Convolution with conical filter function. • Price to be paid : trade off spatial resolution – Line appears more ‘blurred’, it’s exact position is no longer as well defined. – In practice : contrast of lines much reduced. 1 pixel
  • 30. 159.235 Graphics 30 Antialiasing by area sampling. • Convolve line with box filter function ∀ ⇒ Draw line as thin rectangle. • Calculate area of square pixel covered by line Problem : • Equal areas contribute equal intensity, regardless of distance from line centre • Small area in the pixels centre contributes as much as a small area at the pixels edge.
  • 31. 159.235 Graphics 31 Weighted area filtering. • Convolution with a conical filter. • Easy to compute, symmetrical. Lines are same distance from pixel centre, but area of pixel covered is very different in the square case
  • 32. 159.235 Graphics 32 Weighted area filtering. • Diameter is 2 pixels, so overlap occurs – Ensures all of the grid is covered • Area is normalised • Only need to know distance from pixel centre to line • Gupta-Sproull algorithm.
  • 33. 159.235 Graphics 33 Gupta-Sproull algorithm. M NE Calculate distance using features of mid-point algorithm D Angle = ∅v dy dx 22 cos dydx vdx vD + = = φ E
  • 34. 159.235 Graphics 34 Gupta-Sproull algorithm. Calculate distance using features of mid-point algorithm 22 cos dydx vdx vD + = = φ 22 2 dydx dxd D + + = See Foley Van-Dam Sec. 3.17 d is the decision variable.
  • 35. 159.235 Graphics 35 Filter shape. • Cone filter – Simply set pixel to a multiple of the distance • Gaussian filter – Store precomputed values in look up table • Thick lines – Store area intersection in look-up table.
  • 36. 159.235 Graphics 36 Summary of antialiasing lines • Use square unweighted average filter – Poor representation of line. • Weighted average filter better • Use Cone – Symmetrical, only need to know distance – Use decision variable calculated in Bresenham. – Gupta-Sproull algorithm.

Notas del editor

  1. Important algorithm.
  2. Very important.
  3. This is all you need to know on aliasing.
  4. Not examinable.
  5. Only principle of this method important.