Escolar Documentos
Profissional Documentos
Cultura Documentos
COMPUTER GRAPHICS
Algorithms for Graphics Primitives
Material based on
- Computer Graphics with OpenGL, Fourth Edition by Donald Hearn, M. Pauline Baker, and Warren R. Carithers
- Fundamentals of Computer Graphics, Third Edition by by Peter Shirley and Steve Marschner
- Computer Graphics by F. S. Hill
Jaggies in line-drawing
Figure 6-1 Stair-step effect (jaggies) produced when a line is generated as a
series of pixel positions.
Line equations
Figure 6-2 Line path between endpoint positions (x0, y0) and (x end, y end).
yk+1=yk-m
If we process from right to left and m>1, then we have y=-1 and
xk+1=xk-1/m
For negative slopes, look at the the magnitude of m
DDA
Problems of DDA
Accumulation of round-off errors
Calculated pixel positions may drift away from the true line path for
long segments
Rounding operations and floating point arithmetic are
time-consuming
10
11
12
Bresenham
13
Bresenham
We would like to use only integer calculations
Define a decision parameter pk. Letting m=y/x:
x>0
Parameter c is constant and is 2y+x(2b-1) which is
independent of the pixel position and will be eliminated in
the recursive calculation
14
Bresenham
If pixel at yk is closer to the line path than pixel at yk+1 (i.e.
using
where yk+1-yk is either 0 or 1 depending on the sign of pk
First parameter is calculated as
15
Bresenham algorithm
16
Example
17
Example
18
Circle-generating algorithms
Figure 6-11 Circle with center
coordinates (xc , yc) and radius r .
19
Circle-generating algorithms
One could use
Sqrt is time-consuming
20
21
22
23
24
25
Recursive expression
26
27
Example
28
Example
29
Example
Figure 6-15 Pixel positions (solid circles) along a circle path centered on the origin and with radius r = 10, as
calculated by the midpoint circle algorithm. Open (hollow) circles show the symmetry positions in the first
quadrant.
30
Ellipse-generating algorithms
Figure 6-16 Ellipse generated about foci F1 and F2.
31
32
33
34
35
36
Ellipse
37
Ellipse (region 2)
Figure 6-22 Midpoint between candidate pixels at sampling position yk 1 along an
elliptical path.
38
Ellipse
39
40
41
Example
42
Example
43
Example
44
Example
Figure 6-23 Pixel positions along an elliptical path centered on the origin with rx = 8 and ry = 6, using the
midpoint algorithm to calculate locations within the first quadrant.
45
46
47
Polygon filling
For scan line y, the two edges sharing an intersection
48
49
scan line k
At kth position, edges are in sorted order from left to right.
polygon to its top, producing an active edge list (AEL) for each
scan line crossing the polygon boundaries
The active edge list for a scan line contains all edges crossed by that
scan line
50
Edge tables
Figure 6-50 A polygon and its sorted edge table, with edge DC shortened by one unit in the y direction.
51
encountered
Flood-fill
Fill in (recolor) an area that is not defined within a single color
boundary
Paint by replacing a specified interior color instead of searching for
a particular boundary color
52
Boundary-fill
Boundary-ll algorithm starts from an interior point (x, y)
53
54
55
Boundary-fill
56
Flood-fill
Sometimes we want to ll in (or recolor) an area that is
57
Flood-fill
58
Antialiasing
Aliasing: Distortion of information due to low-frequency
sampling (undersampling)
Increase sampling rate in raster systems
Simply display at higher resolution: Requires large frame-buffers!
Apple MacBook Retina Display: Over 5 million on the 15 inch model: With
so high pixel density, your eyes cant discern individual pixels at normal
viewing distance
59
Antialiasing
Blurring to smooth an image
E.g. Sharp transitions from black to white is softened by using a
mixture of gray pixels near the borders
When looking from a distance, eye blends the gracefully varying
shades together
60
61
Supersampling
Figure 6-59 Supersampling subpixel positions along a Figure 6-60 Supersampling subpixel positions
straight-line segment whose left endpoint is at screen in relation to the interior of a line of finite width.
coordinates (10, 20).
62
area
Center subpixel is weighted by a factor of 1/4; the top, bottom, and side
subpixels are each weighted by a factor of 1/8; and the corner subpixels
are each weighted by a factor of 1/16.
63
64
65
66
67
Pixel phasing
On raster systems that can address subpixel positions