SlideShare une entreprise Scribd logo
1  sur  47
Télécharger pour lire hors ligne
Drawing 2D Primitives
Foley & Van Dam, Chapter 3
Topics
•Interactive Graphic Systems
•Drawing lines
•Drawing circles
•Filling polygons
Interactive Graphic System
Application ModelApplication Model
Application ProgramApplication Program
Graphics SystemGraphics System
Interactive Graphic System
Application Model
–Represents data and objects to be displayed on the
output device
Application Program
–Creates, stores into, and retrieves from the application
model
–Handles user-inputs
–Sends output commands to the graphics system:
•Which geometric object to view (point, line, circle,
polygon)
•How to view it (color, line-style, thickness, texture)
Graphics System
–Intermediates between the application program
and the interface hardware:
•Output flow
•Input flow
–Causes the application program to be device-
independent.
Display Hardware
CRT - Cathode Ray Tube
Cathode
(electron gun)
deflection
yoke
focusing
anode
shadow mask
and phosphor
coated screen
phosphors on
glass screen
shadow mask
electron guns
Raster Scan (CRT)
Scan line
Display Hardware
FED - Field Emission Display
Catode electrodes
Microtips
(Emitters)
Phospor
Anode
Image Representation in Raster Displays
pixel
I
R
G
B
Raster Display
36147951
15927660
127845255
558217155
Frame Buffer
Video
Controller
Display
Controller
Keyboard
Mouse
Display
commands
Interaction
data
Graphics
system
Terminology
Pixel: Picture element.
- Smallest accessible element in picture
- Assume rectangular or circular shape
Aspect Ratio: Ratio between physical dimensions of a pixel (not necessarily 1)
Dynamic Range: The ratio between the minimal (not zero!) and the maximal
light intensity a display pixel can emit
Resolution: The number of distinguishable rows and columns in the device.
Measured in:
- Absolute values (1K x 1K) or,
- Density values (300 dpi [=dots per inch])
Screen Space: A discrete Cartesian coordinate system of the screen pixels
Object Space: The Cartesian coordinate system of the universe, in which the
objects (to be displayed) are embedded
Scan Conversion
The conversion from a geometrical
representation of an object to pixels in a
raster display
(x0,y0)
(x1,y1)
Representations
Implicit formula:
Constraint(s) expressed as
A k-dimensional surface embedded in n-dimensions
Explicit formula:
For each x define y as y=f(x)
Good only for "functions".
Parametric formula:
Depending on free parameter(s)
For k-dimensional surface there are k free parameters
f(x,y,..)=0
fi(x1,x2,..,xn)=0 ; i=1..n-k
x=fx(t)
y=fy(t)
Line in 2 dimensions
•Implicit representation:
•Explicit representation:
•Parametric representation:
0=++ γβα yx
01
01
xx
yy
mBmxy
−
−
=+=
]1..0[)( 010 ∈−+= ttPPPP





=
y
x
P
x
P0
P1
x0
y1
y0
x1B
Scan Conversion - Lines
slope = m =
y1 - y0
x1 - x0
Assume |m| ≤ 1
Assume x0 ≤ x1
Basic Algorithm
For x = x0 to x1
y = mx + B
PlotPixel(x,round(y))
end;
offset= B = y1-mx1
For each iteration: 1 float multiplication, 1 addition, 1 round
y = mx + B
(x0,y0)
(x1,y1)
Scan Conversion - Lines
Incremental Algorithm
yi+1 = mxi+1 + B = m(xi + ∆x) + B = yi + m∆x
if ∆x = 1 then yi+1 = yi + m
Algorithm
For x = x0 to x1
PlotPixel(x,round(y))
end;
y=y0
y = y + m
Scan Conversion - Lines
( xi,Round(yi) )
( xi+1, yi+m )
( xi, yi )
( xi+1,Round(yi+m) )
Pseudo Code for Basic Line Drawing
Assume x1>x0 and line slope absolute value is ≤ 1
Line(x0,y0,x1,y1)
begin
float dx, dy, x, y, slope;
dx := x1-x0;
dy := y1-y0;
slope := dy/dx;
y := y0;
for x:=x0 to x1 do
begin
PlotPixel( x,Round(y) );
y := y+slope;
end;
end;
Basic Line Drawing
Symmetric Cases:
|m| ≥ 1
For y = y0 to y1
x = x + 1/m
PlotPixel(round(x),y)
end;
x = x0
Special Cases:
m = ± 1 (diagonals)
m = 0, ∞ (horizontal, vertical)
Symmetric Cases:
if x0 > x1 for |m| ≤ 1 or y0 > y1 for |m| ≥ 1
swap((x0,y0),(x1,y1))
For each iteration:
•1 addition, 1 rounding
Drawbacks:
• Accumulated error
• Floating point arithmetic
• Round operations
Midpoint (Bresenham) Line Drawing
Assumptions:
• x0 < x1 , y0 < y1
• 0 < slope < 1
M
Q
E
NE
(xp,yp)
Given (xp,yp), the next pixel is E = (xp +1,yp) or NE = (xp+1,yp+1)
Bresenham: sign(M-Q) determines NE or E
M = (xp +1,yp +1/2)
Midpoint (Bresenham) Line Drawing
y = x + B
dy
dx
Implicit form of a line:
f(x,y) = ax + by + c = 0
Decision Variable :
d = f(M) = f(xp +1,yp +1/2) = a(xp +1) + b(yp +1/2) + c
• choose NE if d > 0
• choose E if d ≤ 0
f(x,y) = dy x - dx y + B dx = 0
f(x,y) = 0
f(x,y) > 0
f(x,y) < 0(a>0)
Midpoint (Bresenham) Line Drawing
If E was chosen at xp + 1
What happens at xp + 2 ?
M = (xp +2,yp +1/2)
dnew = f(xp +2,yp +1/2) = a(xp +2) + b(yp +1/2) + c
dold = f(xp +1,yp +1/2) = a(xp +1) + b(yp +1/2) + c
dnew = dold + a = dold + dy
dnew = dold + ∆E
If NE was chosen at xp + 1
M = (xp +2,yp +3/2)
dnew = f(xp +2,yp +3/2) = a(xp +2) + b(yp +3/2) + c
dold = f(xp +1,yp +1/2) = a(xp +1) + b(yp +1/2) + c
dnew = dold + a + b = dold + dy - dx
dnew = dold + ∆NE
M
Q
E
NE
(xp,yp)
MM
Midpoint (Bresenham) Line Drawing
Initialization:
First point = (x0,y0), first MidPoint = (x0+1,y0+1/2)
dstart = f(x0 +1,y0+1/2) = a(x0 +1) + b(y0 +1/2) +c
= ax0 + by0 + c + a + b/2
= f(x0,y0) + a + b/2 = a + b/2
dstart =dy - dx/2
Enhancement:
To eliminate fractions, define:
f(x,y) = 2(ax + by + c) = 0
dstart =2dy - dx
∆E=2dy
∆NE=2(dy-dx)
Midpoint (Bresenham) Line Drawing
•The sign of f(x0+1,y0+1/2) indicates whether to move East
or North-East
•At the beginning d=f(x0+1,y0+1/2)=2dy-dx
•The increment in d (after this step) is:
If we moved East: ∆E=2dy
If we moved North-East: ∆NE=2dy-2dx
Comments:
•Integer arithmetic (dx and dy are integers)
•One addition for each iteration
•No accumulated errors
•By symmetry, we deal with 0>slope>-1
Pseudo Code for Midpoint Line Drawing
Assume x1>x0 and 0 < slope ≤ 1
Line(x0,y0,x1,y1)
begin
int dx, dy, x, y, d, ∆E, ∆ΝE ;
x:= x0; y=y0;
dx := x1-x0; dy := y1-y0;
d := 2*dy-dx;
∆E := 2*dy; ∆ΝΕ := 2*(dy-dx);
PlotPixel(x,y);
while(x < x1) do
if (d < 0) then
d:=d+ ∆E;
x:=x+1;
end;
else
d:=d+ ∆ΝE;
x:=x+1;
y:=y+1;
end;
PlotPixel(x,y);
end;
end;
Scan Conversion - Circles
Implicit representation (centered at the origin, radius R):
Explicit representation:
Parametric representation:
0222
=−+ Ryx
( )
( )
]2..0[
sin
cos
π∈





=





t
tR
tR
y
x
22
xRy −±=
x
R
Scan Conversion - Circles
Basic Algorithm
For x = -R to R
y = sqrt(R2-x2)
PlotPixel(x,round(y))
PlotPixel(x,-round(y))
end;
Comments:
• Square-root operations are expensive
• Floating point arithmetic
• Large gap for x values close to R
Scan Conversion - Circles
Exploiting Eight-Way Symmetry
For a circle centered at the origin:
If (x,y) is on the circle then
(y,x) (y,-x) (x,-y) (-x,-y) (-y,-x) (-y,x) (-x,y)
are on the circle as well.
Therefore we need to compute only one octant (45o) segment.
(x,y)
(y,x)
(y,-x)
(x,-y)(-x,-y)
(-y,x)
(-y,-x)
(-x,y)
Scan Conversion - Circles
CirclePoints(x, y)
begin
PlotPixel(x,y);
PlotPixel(y,x);
PlotPixel(y,-x);
PlotPixel(x,-y);
PlotPixel(-x,-y);
PlotPixel(-y,-x);
PlotPixel(-y,x);
PlotPixel(-x,y);
end;
(x,y)
(y,x)
(y,-x)
(x,-y)(-x,-y)
(-y,x)
(-y,-x)
(-x,y)
Circle Midpoint (for one octant)
• We start from (x0,y0)=(0,R)
• One can move either East or South-East
• Again, d(x,y) will be a threshold criteria at the midpoint
(The circle is located at (0,0) with radius R)
Circle Midpoint (for one octant)
d(x,y)=f(x,y) = x2 + y2 -R2 = 0
f(x,y) = 0
f(x,y) < 0
f(x,y) > 0
Threshold Criteria:
Circle Midpoint (for one octant)
• At the beginning
dstart= d(x0+1,y0-1/2)
= d(1,R-1/2) = 5/4 - R
• If d<0 we move East:
∆E = d(x0+2,y0-1/2) - d(x0+1,y0-1/2) = 2x0+3
• if d>0 we move South-East:
∆SE = d(x0+2,y0-3/2) - d(x0+1,y0-1/2) = 2(x0-y0)+5
• ∆E and ∆SE are not constant anymore
• Since d is incremented by integer values, we can use
dstart = 1-R
yielding an integer algorithm. This has no affect on the
threshold criteria.
x0
y0
Pseudo Code for Circle Midpoint
MidpointCircle (R)
begin
int x, y, d;
x := 0;
y :=R;
d := 5.0/4.0-R;
CirclePoints(x,y);
while ( y>x ) do
if ( d<0 ) then /* East */
d := d+2x+3;
x := x+1;
end;
else /* South East */
d := d+2(x-y)+5;
x := x+1;
y := y-1;
end;
CirclePoints( x,y ); /* Mirror to create the other seven octants */
end;
Pseudo Code for Circle Midpoint
MidpointCircle (R)
begin
int x, y, d;
x := 0;
y :=R;
d := 1-R; /* originally d := 5.0/4.0 - R */
CirclePoints(x,y);
while ( y>x ) do
if ( d<0 ) then /* East */
d := d+2x+3; /* Multiplication! */
x := x+1;
end;
else /* South East */
d := d+2(x-y)+5; /* Multiplication! */
x := x+1;
y := y-1;
end;
CirclePoints( x,y ); /* Mirror to create the other seven octants */
end;
Pseudo Code for Circle MidpointMidpointCircle (R)
begin
int x, y, d;
x := 0;
y :=R;
d := 1-R; /* originally d := 5.0/4.0 - R */
∆E = 3;
∆SE = -2R+5;
CirclePoints(x,y);
while ( y>x ) do
if ( d<0 ) then /* East */
d := d+∆E; /* See Foley & van Dam pg. 87 */
∆E := ∆E+2;
∆SE := ∆SE+2;
x := x+1;
end;
else /* South East */
d := d+∆SE; /* See Foley & van Dam pg. 87 */
∆E := ∆E+2;
∆SE := ∆SE+4;
x := x+1;
y := y-1;
end;
CirclePoints( x,y ); /* Mirror to create the other seven octants */
end;
Circle Midpoint
Polygon Fill
Representation:
Polygon = V0, V1, V2, .. Vn
Vi=(xi,yi) - vertex
Ei=(vi,vi+1) - edge
En=(vn,v0)
v0
v1
v5
v4
v3
v2
v6
vertex
edge
E0
E1
E6
Scan Conversion - Polygon Fill
Problem: Given a closed 2D polygon, fill its interior with a
specified color, on a graphics display
Assumption: Polygon is simple, i.e. no self intersections,
and simply connected, i.e. without holes
Solutions:
•Flood fill
•Scan Conversion
Flood Fill Algorithm
•Let P be a polygon with n vertices, v0 .. vn-1
•Denote vn=v0
•Let c be a color to paint P
•Let p=(x,y) be a point in P
Flood Fill Algorithm
FloodFill(P,x,y,c)
if (OnBoundary(x,y,P) or Colored (x,y,c))
then return;
else begin
PlotPixel(x,y,c);
FloodFill(P,x+1,y,c);
FloodFill(P,x,y+1,c);
FloodFill(P,x,y-1,c);
FloodFill(P,x-1,y,c);
end;
Slow algorithm due to recursion, needs initial point
Fill Polygon
Question: How do we know if a given point is inside or
outside a polygon?
Scan Conversion – Basic Algorithm
ScanConvert (P,c)
For j:=0 to ScreenYMax do
I := points of intersection of edges
from P with line y=j;
Sort I in increasing x order and fill
with color c alternating segments;
end;
Question: How do we find the intersecting edges?
•Let P be a polygon with n vertices, v0 .. vn-1
•Denote vn=v0
•Let c be a color to paint P
Scan Conversion – Fill Polygon
What happens in with these cases?
Scan Conversion – Fill Polygon
Intersections at pixel coordinates
Rule: In the odd/even count, we count ymin vertices of an edge,
but not ymax vertices
Vertex B is counted once because ymin of (A,B)
Vertex E is not counted because ymax of both (D, E) and (E, F)
Vertex H is counted twice because ymin of both (G, H) and (H, I)
A
B
C
D
E
F
I
H
G
Fill Polygon – Optimized Algorithm
ScanConvert(P,c)
Sort all edges E={Ej} in increasing MinY(Ej ) order.
A := ∅;
For k :=0 to ScreenYMax do
For each Ej ∈ E,
if MinY(Ej)≤ k A := A ∪ Ej ; E=E- Ej
For each Ej ∈ A,
if MaxY(Ej)≤ k A := A – Ej
I:=Points of intersection of members
from A with line y=k;
Sort I in increasing x order and draw
with color c alternating segments;
end;
Uses a list of “active” edges A (edges currently intersecting the scan line)
Fill Polygon – Optimized Algorithm
3 5 7
4 10 15
A
12
ymin
ymax
3 12
E
Implementation with linked lists
Flood Fill vs. Scan Conversion
•Very simple.
•Requires a seed point
•Requires large stack size
•Common in paint
packages
•More complex
•No seed point is required
•Requires small stack size
•Used in image rendering
Flood Fill Scan Conversion

Contenu connexe

Tendances

Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithmsMohammad Sadiq
 
Computer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and EllipseComputer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and Ellipse2013901097
 
Howard, anton cálculo ii- um novo horizonte - exercicio resolvidos v2
Howard, anton   cálculo ii- um novo horizonte - exercicio resolvidos v2Howard, anton   cálculo ii- um novo horizonte - exercicio resolvidos v2
Howard, anton cálculo ii- um novo horizonte - exercicio resolvidos v2Breno Costa
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmNeha Kaurav
 
Lec05 circle ellipse
Lec05 circle ellipseLec05 circle ellipse
Lec05 circle ellipseMaaz Rizwan
 
[4] num integration
[4] num integration[4] num integration
[4] num integrationikhulsys
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesAnkit Garg
 
Comuter graphics bresenhams circle drawing algorithm
Comuter graphics bresenhams circle drawing algorithmComuter graphics bresenhams circle drawing algorithm
Comuter graphics bresenhams circle drawing algorithmRachana Marathe
 
Howard, anton calculo i- um novo horizonte - exercicio resolvidos v1
Howard, anton   calculo i- um novo horizonte - exercicio resolvidos v1Howard, anton   calculo i- um novo horizonte - exercicio resolvidos v1
Howard, anton calculo i- um novo horizonte - exercicio resolvidos v1cideni
 
Finite elements : basis functions
Finite elements : basis functionsFinite elements : basis functions
Finite elements : basis functionsTarun Gehlot
 
24 double integral over polar coordinate
24 double integral over polar coordinate24 double integral over polar coordinate
24 double integral over polar coordinatemath267
 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivationMazharul Islam
 

Tendances (20)

Unit 3
Unit 3Unit 3
Unit 3
 
Geometry Transformation
Geometry TransformationGeometry Transformation
Geometry Transformation
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 
Computer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and EllipseComputer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and Ellipse
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
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)
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Howard, anton cálculo ii- um novo horizonte - exercicio resolvidos v2
Howard, anton   cálculo ii- um novo horizonte - exercicio resolvidos v2Howard, anton   cálculo ii- um novo horizonte - exercicio resolvidos v2
Howard, anton cálculo ii- um novo horizonte - exercicio resolvidos v2
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing Algorithm
 
Lec05 circle ellipse
Lec05 circle ellipseLec05 circle ellipse
Lec05 circle ellipse
 
[4] num integration
[4] num integration[4] num integration
[4] num integration
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniques
 
Comuter graphics bresenhams circle drawing algorithm
Comuter graphics bresenhams circle drawing algorithmComuter graphics bresenhams circle drawing algorithm
Comuter graphics bresenhams circle drawing algorithm
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Howard, anton calculo i- um novo horizonte - exercicio resolvidos v1
Howard, anton   calculo i- um novo horizonte - exercicio resolvidos v1Howard, anton   calculo i- um novo horizonte - exercicio resolvidos v1
Howard, anton calculo i- um novo horizonte - exercicio resolvidos v1
 
Finite elements : basis functions
Finite elements : basis functionsFinite elements : basis functions
Finite elements : basis functions
 
Dda line-algorithm
Dda line-algorithmDda line-algorithm
Dda line-algorithm
 
Lect3cg2011
Lect3cg2011Lect3cg2011
Lect3cg2011
 
24 double integral over polar coordinate
24 double integral over polar coordinate24 double integral over polar coordinate
24 double integral over polar coordinate
 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivation
 

Similaire à Open GL T0074 56 sm4

Output Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and MultimediaOutput Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and Multimediasaranyan75
 
Computer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivesComputer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivessaranyan75
 
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohichapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi54MahakBansal
 
Modeling Transformations
Modeling TransformationsModeling Transformations
Modeling TransformationsTarun Gehlot
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsAmol Gaikwad
 
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
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxNaveenaKarthik3
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsDrishti Bhalla
 
Open GL 04 linealgos
Open GL 04 linealgosOpen GL 04 linealgos
Open GL 04 linealgosRoziq Bahtiar
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output PrimitivesPrathimaBaliga
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1aravindangc
 
Clustering and Factorization using Apache SystemML by Alexandre V Evfimievski
Clustering and Factorization using Apache SystemML by  Alexandre V EvfimievskiClustering and Factorization using Apache SystemML by  Alexandre V Evfimievski
Clustering and Factorization using Apache SystemML by Alexandre V EvfimievskiArvind Surve
 
Clustering and Factorization using Apache SystemML by Alexandre V Evfimievski
Clustering and Factorization using Apache SystemML by  Alexandre V EvfimievskiClustering and Factorization using Apache SystemML by  Alexandre V Evfimievski
Clustering and Factorization using Apache SystemML by Alexandre V EvfimievskiArvind Surve
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxKokebe2
 
Computer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptComputer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptAliZaib71
 

Similaire à Open GL T0074 56 sm4 (20)

Output Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and MultimediaOutput Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and Multimedia
 
Computer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivesComputer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitives
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohichapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
 
Modeling Transformations
Modeling TransformationsModeling Transformations
Modeling Transformations
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithms
 
10 linescan
10 linescan10 linescan
10 linescan
 
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...
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptx
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer Graphics
 
Open GL 04 linealgos
Open GL 04 linealgosOpen GL 04 linealgos
Open GL 04 linealgos
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output Primitives
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1
 
2.circle
2.circle2.circle
2.circle
 
CG-Lecture3.pptx
CG-Lecture3.pptxCG-Lecture3.pptx
CG-Lecture3.pptx
 
2D_line_circle.ppt
2D_line_circle.ppt2D_line_circle.ppt
2D_line_circle.ppt
 
Clustering and Factorization using Apache SystemML by Alexandre V Evfimievski
Clustering and Factorization using Apache SystemML by  Alexandre V EvfimievskiClustering and Factorization using Apache SystemML by  Alexandre V Evfimievski
Clustering and Factorization using Apache SystemML by Alexandre V Evfimievski
 
Clustering and Factorization using Apache SystemML by Alexandre V Evfimievski
Clustering and Factorization using Apache SystemML by  Alexandre V EvfimievskiClustering and Factorization using Apache SystemML by  Alexandre V Evfimievski
Clustering and Factorization using Apache SystemML by Alexandre V Evfimievski
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptx
 
Computer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptComputer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.ppt
 

Plus de Roziq Bahtiar

Techarea company profile
Techarea company profileTecharea company profile
Techarea company profileRoziq Bahtiar
 
static and dynamic routing
static and dynamic routingstatic and dynamic routing
static and dynamic routingRoziq Bahtiar
 
Perintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating SistemPerintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating SistemRoziq Bahtiar
 
Pengantar algoritma pemrograman
Pengantar algoritma pemrogramanPengantar algoritma pemrograman
Pengantar algoritma pemrogramanRoziq Bahtiar
 
Flowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulatFlowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulatRoziq Bahtiar
 
Tarby magazine salafiyah kajen
Tarby magazine  salafiyah kajenTarby magazine  salafiyah kajen
Tarby magazine salafiyah kajenRoziq Bahtiar
 
7. pemrograman struktur
7. pemrograman struktur7. pemrograman struktur
7. pemrograman strukturRoziq Bahtiar
 
6. pemrograman pointer
6. pemrograman pointer6. pemrograman pointer
6. pemrograman pointerRoziq Bahtiar
 
5. pemrograman array dan_string
5. pemrograman array dan_string5. pemrograman array dan_string
5. pemrograman array dan_stringRoziq Bahtiar
 
4. pemrograman fungsi
4. pemrograman fungsi4. pemrograman fungsi
4. pemrograman fungsiRoziq Bahtiar
 
3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrograman3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrogramanRoziq Bahtiar
 
2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrograman2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrogramanRoziq Bahtiar
 
1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_data1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_dataRoziq Bahtiar
 

Plus de Roziq Bahtiar (20)

Techarea company profile
Techarea company profileTecharea company profile
Techarea company profile
 
static and dynamic routing
static and dynamic routingstatic and dynamic routing
static and dynamic routing
 
Perintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating SistemPerintah perintah dasar linux Operating Sistem
Perintah perintah dasar linux Operating Sistem
 
Pengantar algoritma pemrograman
Pengantar algoritma pemrogramanPengantar algoritma pemrograman
Pengantar algoritma pemrograman
 
Flowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulatFlowchart progrm linear bilangan bulat
Flowchart progrm linear bilangan bulat
 
Tarby magazine salafiyah kajen
Tarby magazine  salafiyah kajenTarby magazine  salafiyah kajen
Tarby magazine salafiyah kajen
 
Pcd 10
Pcd 10Pcd 10
Pcd 10
 
Pcd 11
Pcd 11Pcd 11
Pcd 11
 
7. pemrograman struktur
7. pemrograman struktur7. pemrograman struktur
7. pemrograman struktur
 
6. pemrograman pointer
6. pemrograman pointer6. pemrograman pointer
6. pemrograman pointer
 
5. pemrograman array dan_string
5. pemrograman array dan_string5. pemrograman array dan_string
5. pemrograman array dan_string
 
4. pemrograman fungsi
4. pemrograman fungsi4. pemrograman fungsi
4. pemrograman fungsi
 
3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrograman3. teknik looping dalam_pemrograman
3. teknik looping dalam_pemrograman
 
2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrograman2. teknik pemilihan dalam_pemrograman
2. teknik pemilihan dalam_pemrograman
 
1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_data1. variable identifier dan_tipe_data
1. variable identifier dan_tipe_data
 
Alpro tutor
Alpro tutorAlpro tutor
Alpro tutor
 
Pcd 7
Pcd 7Pcd 7
Pcd 7
 
Pcd 5
Pcd 5Pcd 5
Pcd 5
 
Pcd 4
Pcd 4Pcd 4
Pcd 4
 
Eigen
EigenEigen
Eigen
 

Dernier

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
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
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
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
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
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
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 

Dernier (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
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...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
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
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
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
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
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
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 

Open GL T0074 56 sm4

  • 1. Drawing 2D Primitives Foley & Van Dam, Chapter 3
  • 2. Topics •Interactive Graphic Systems •Drawing lines •Drawing circles •Filling polygons
  • 3. Interactive Graphic System Application ModelApplication Model Application ProgramApplication Program Graphics SystemGraphics System
  • 4. Interactive Graphic System Application Model –Represents data and objects to be displayed on the output device Application Program –Creates, stores into, and retrieves from the application model –Handles user-inputs –Sends output commands to the graphics system: •Which geometric object to view (point, line, circle, polygon) •How to view it (color, line-style, thickness, texture)
  • 5. Graphics System –Intermediates between the application program and the interface hardware: •Output flow •Input flow –Causes the application program to be device- independent.
  • 6. Display Hardware CRT - Cathode Ray Tube Cathode (electron gun) deflection yoke focusing anode shadow mask and phosphor coated screen phosphors on glass screen shadow mask electron guns
  • 8. Display Hardware FED - Field Emission Display Catode electrodes Microtips (Emitters) Phospor Anode
  • 9. Image Representation in Raster Displays pixel I R G B
  • 11. Terminology Pixel: Picture element. - Smallest accessible element in picture - Assume rectangular or circular shape Aspect Ratio: Ratio between physical dimensions of a pixel (not necessarily 1) Dynamic Range: The ratio between the minimal (not zero!) and the maximal light intensity a display pixel can emit Resolution: The number of distinguishable rows and columns in the device. Measured in: - Absolute values (1K x 1K) or, - Density values (300 dpi [=dots per inch]) Screen Space: A discrete Cartesian coordinate system of the screen pixels Object Space: The Cartesian coordinate system of the universe, in which the objects (to be displayed) are embedded
  • 12. Scan Conversion The conversion from a geometrical representation of an object to pixels in a raster display (x0,y0) (x1,y1)
  • 13. Representations Implicit formula: Constraint(s) expressed as A k-dimensional surface embedded in n-dimensions Explicit formula: For each x define y as y=f(x) Good only for "functions". Parametric formula: Depending on free parameter(s) For k-dimensional surface there are k free parameters f(x,y,..)=0 fi(x1,x2,..,xn)=0 ; i=1..n-k x=fx(t) y=fy(t)
  • 14. Line in 2 dimensions •Implicit representation: •Explicit representation: •Parametric representation: 0=++ γβα yx 01 01 xx yy mBmxy − − =+= ]1..0[)( 010 ∈−+= ttPPPP      = y x P x P0 P1 x0 y1 y0 x1B
  • 15. Scan Conversion - Lines slope = m = y1 - y0 x1 - x0 Assume |m| ≤ 1 Assume x0 ≤ x1 Basic Algorithm For x = x0 to x1 y = mx + B PlotPixel(x,round(y)) end; offset= B = y1-mx1 For each iteration: 1 float multiplication, 1 addition, 1 round y = mx + B (x0,y0) (x1,y1)
  • 16. Scan Conversion - Lines Incremental Algorithm yi+1 = mxi+1 + B = m(xi + ∆x) + B = yi + m∆x if ∆x = 1 then yi+1 = yi + m Algorithm For x = x0 to x1 PlotPixel(x,round(y)) end; y=y0 y = y + m
  • 17. Scan Conversion - Lines ( xi,Round(yi) ) ( xi+1, yi+m ) ( xi, yi ) ( xi+1,Round(yi+m) )
  • 18. Pseudo Code for Basic Line Drawing Assume x1>x0 and line slope absolute value is ≤ 1 Line(x0,y0,x1,y1) begin float dx, dy, x, y, slope; dx := x1-x0; dy := y1-y0; slope := dy/dx; y := y0; for x:=x0 to x1 do begin PlotPixel( x,Round(y) ); y := y+slope; end; end;
  • 19. Basic Line Drawing Symmetric Cases: |m| ≥ 1 For y = y0 to y1 x = x + 1/m PlotPixel(round(x),y) end; x = x0 Special Cases: m = ± 1 (diagonals) m = 0, ∞ (horizontal, vertical) Symmetric Cases: if x0 > x1 for |m| ≤ 1 or y0 > y1 for |m| ≥ 1 swap((x0,y0),(x1,y1)) For each iteration: •1 addition, 1 rounding Drawbacks: • Accumulated error • Floating point arithmetic • Round operations
  • 20. Midpoint (Bresenham) Line Drawing Assumptions: • x0 < x1 , y0 < y1 • 0 < slope < 1 M Q E NE (xp,yp) Given (xp,yp), the next pixel is E = (xp +1,yp) or NE = (xp+1,yp+1) Bresenham: sign(M-Q) determines NE or E M = (xp +1,yp +1/2)
  • 21. Midpoint (Bresenham) Line Drawing y = x + B dy dx Implicit form of a line: f(x,y) = ax + by + c = 0 Decision Variable : d = f(M) = f(xp +1,yp +1/2) = a(xp +1) + b(yp +1/2) + c • choose NE if d > 0 • choose E if d ≤ 0 f(x,y) = dy x - dx y + B dx = 0 f(x,y) = 0 f(x,y) > 0 f(x,y) < 0(a>0)
  • 22. Midpoint (Bresenham) Line Drawing If E was chosen at xp + 1 What happens at xp + 2 ? M = (xp +2,yp +1/2) dnew = f(xp +2,yp +1/2) = a(xp +2) + b(yp +1/2) + c dold = f(xp +1,yp +1/2) = a(xp +1) + b(yp +1/2) + c dnew = dold + a = dold + dy dnew = dold + ∆E If NE was chosen at xp + 1 M = (xp +2,yp +3/2) dnew = f(xp +2,yp +3/2) = a(xp +2) + b(yp +3/2) + c dold = f(xp +1,yp +1/2) = a(xp +1) + b(yp +1/2) + c dnew = dold + a + b = dold + dy - dx dnew = dold + ∆NE M Q E NE (xp,yp) MM
  • 23. Midpoint (Bresenham) Line Drawing Initialization: First point = (x0,y0), first MidPoint = (x0+1,y0+1/2) dstart = f(x0 +1,y0+1/2) = a(x0 +1) + b(y0 +1/2) +c = ax0 + by0 + c + a + b/2 = f(x0,y0) + a + b/2 = a + b/2 dstart =dy - dx/2 Enhancement: To eliminate fractions, define: f(x,y) = 2(ax + by + c) = 0 dstart =2dy - dx ∆E=2dy ∆NE=2(dy-dx)
  • 24. Midpoint (Bresenham) Line Drawing •The sign of f(x0+1,y0+1/2) indicates whether to move East or North-East •At the beginning d=f(x0+1,y0+1/2)=2dy-dx •The increment in d (after this step) is: If we moved East: ∆E=2dy If we moved North-East: ∆NE=2dy-2dx Comments: •Integer arithmetic (dx and dy are integers) •One addition for each iteration •No accumulated errors •By symmetry, we deal with 0>slope>-1
  • 25. Pseudo Code for Midpoint Line Drawing Assume x1>x0 and 0 < slope ≤ 1 Line(x0,y0,x1,y1) begin int dx, dy, x, y, d, ∆E, ∆ΝE ; x:= x0; y=y0; dx := x1-x0; dy := y1-y0; d := 2*dy-dx; ∆E := 2*dy; ∆ΝΕ := 2*(dy-dx); PlotPixel(x,y); while(x < x1) do if (d < 0) then d:=d+ ∆E; x:=x+1; end; else d:=d+ ∆ΝE; x:=x+1; y:=y+1; end; PlotPixel(x,y); end; end;
  • 26. Scan Conversion - Circles Implicit representation (centered at the origin, radius R): Explicit representation: Parametric representation: 0222 =−+ Ryx ( ) ( ) ]2..0[ sin cos π∈      =      t tR tR y x 22 xRy −±= x R
  • 27. Scan Conversion - Circles Basic Algorithm For x = -R to R y = sqrt(R2-x2) PlotPixel(x,round(y)) PlotPixel(x,-round(y)) end; Comments: • Square-root operations are expensive • Floating point arithmetic • Large gap for x values close to R
  • 28. Scan Conversion - Circles Exploiting Eight-Way Symmetry For a circle centered at the origin: If (x,y) is on the circle then (y,x) (y,-x) (x,-y) (-x,-y) (-y,-x) (-y,x) (-x,y) are on the circle as well. Therefore we need to compute only one octant (45o) segment. (x,y) (y,x) (y,-x) (x,-y)(-x,-y) (-y,x) (-y,-x) (-x,y)
  • 29. Scan Conversion - Circles CirclePoints(x, y) begin PlotPixel(x,y); PlotPixel(y,x); PlotPixel(y,-x); PlotPixel(x,-y); PlotPixel(-x,-y); PlotPixel(-y,-x); PlotPixel(-y,x); PlotPixel(-x,y); end; (x,y) (y,x) (y,-x) (x,-y)(-x,-y) (-y,x) (-y,-x) (-x,y)
  • 30. Circle Midpoint (for one octant) • We start from (x0,y0)=(0,R) • One can move either East or South-East • Again, d(x,y) will be a threshold criteria at the midpoint (The circle is located at (0,0) with radius R)
  • 31. Circle Midpoint (for one octant) d(x,y)=f(x,y) = x2 + y2 -R2 = 0 f(x,y) = 0 f(x,y) < 0 f(x,y) > 0 Threshold Criteria:
  • 32. Circle Midpoint (for one octant) • At the beginning dstart= d(x0+1,y0-1/2) = d(1,R-1/2) = 5/4 - R • If d<0 we move East: ∆E = d(x0+2,y0-1/2) - d(x0+1,y0-1/2) = 2x0+3 • if d>0 we move South-East: ∆SE = d(x0+2,y0-3/2) - d(x0+1,y0-1/2) = 2(x0-y0)+5 • ∆E and ∆SE are not constant anymore • Since d is incremented by integer values, we can use dstart = 1-R yielding an integer algorithm. This has no affect on the threshold criteria. x0 y0
  • 33. Pseudo Code for Circle Midpoint MidpointCircle (R) begin int x, y, d; x := 0; y :=R; d := 5.0/4.0-R; CirclePoints(x,y); while ( y>x ) do if ( d<0 ) then /* East */ d := d+2x+3; x := x+1; end; else /* South East */ d := d+2(x-y)+5; x := x+1; y := y-1; end; CirclePoints( x,y ); /* Mirror to create the other seven octants */ end;
  • 34. Pseudo Code for Circle Midpoint MidpointCircle (R) begin int x, y, d; x := 0; y :=R; d := 1-R; /* originally d := 5.0/4.0 - R */ CirclePoints(x,y); while ( y>x ) do if ( d<0 ) then /* East */ d := d+2x+3; /* Multiplication! */ x := x+1; end; else /* South East */ d := d+2(x-y)+5; /* Multiplication! */ x := x+1; y := y-1; end; CirclePoints( x,y ); /* Mirror to create the other seven octants */ end;
  • 35. Pseudo Code for Circle MidpointMidpointCircle (R) begin int x, y, d; x := 0; y :=R; d := 1-R; /* originally d := 5.0/4.0 - R */ ∆E = 3; ∆SE = -2R+5; CirclePoints(x,y); while ( y>x ) do if ( d<0 ) then /* East */ d := d+∆E; /* See Foley & van Dam pg. 87 */ ∆E := ∆E+2; ∆SE := ∆SE+2; x := x+1; end; else /* South East */ d := d+∆SE; /* See Foley & van Dam pg. 87 */ ∆E := ∆E+2; ∆SE := ∆SE+4; x := x+1; y := y-1; end; CirclePoints( x,y ); /* Mirror to create the other seven octants */ end;
  • 37. Polygon Fill Representation: Polygon = V0, V1, V2, .. Vn Vi=(xi,yi) - vertex Ei=(vi,vi+1) - edge En=(vn,v0) v0 v1 v5 v4 v3 v2 v6 vertex edge E0 E1 E6
  • 38. Scan Conversion - Polygon Fill Problem: Given a closed 2D polygon, fill its interior with a specified color, on a graphics display Assumption: Polygon is simple, i.e. no self intersections, and simply connected, i.e. without holes Solutions: •Flood fill •Scan Conversion
  • 39. Flood Fill Algorithm •Let P be a polygon with n vertices, v0 .. vn-1 •Denote vn=v0 •Let c be a color to paint P •Let p=(x,y) be a point in P
  • 40. Flood Fill Algorithm FloodFill(P,x,y,c) if (OnBoundary(x,y,P) or Colored (x,y,c)) then return; else begin PlotPixel(x,y,c); FloodFill(P,x+1,y,c); FloodFill(P,x,y+1,c); FloodFill(P,x,y-1,c); FloodFill(P,x-1,y,c); end; Slow algorithm due to recursion, needs initial point
  • 41. Fill Polygon Question: How do we know if a given point is inside or outside a polygon?
  • 42. Scan Conversion – Basic Algorithm ScanConvert (P,c) For j:=0 to ScreenYMax do I := points of intersection of edges from P with line y=j; Sort I in increasing x order and fill with color c alternating segments; end; Question: How do we find the intersecting edges? •Let P be a polygon with n vertices, v0 .. vn-1 •Denote vn=v0 •Let c be a color to paint P
  • 43. Scan Conversion – Fill Polygon What happens in with these cases?
  • 44. Scan Conversion – Fill Polygon Intersections at pixel coordinates Rule: In the odd/even count, we count ymin vertices of an edge, but not ymax vertices Vertex B is counted once because ymin of (A,B) Vertex E is not counted because ymax of both (D, E) and (E, F) Vertex H is counted twice because ymin of both (G, H) and (H, I) A B C D E F I H G
  • 45. Fill Polygon – Optimized Algorithm ScanConvert(P,c) Sort all edges E={Ej} in increasing MinY(Ej ) order. A := ∅; For k :=0 to ScreenYMax do For each Ej ∈ E, if MinY(Ej)≤ k A := A ∪ Ej ; E=E- Ej For each Ej ∈ A, if MaxY(Ej)≤ k A := A – Ej I:=Points of intersection of members from A with line y=k; Sort I in increasing x order and draw with color c alternating segments; end; Uses a list of “active” edges A (edges currently intersecting the scan line)
  • 46. Fill Polygon – Optimized Algorithm 3 5 7 4 10 15 A 12 ymin ymax 3 12 E Implementation with linked lists
  • 47. Flood Fill vs. Scan Conversion •Very simple. •Requires a seed point •Requires large stack size •Common in paint packages •More complex •No seed point is required •Requires small stack size •Used in image rendering Flood Fill Scan Conversion