CG CH3 Scan Conversion2
CG CH3 Scan Conversion2
Chapter Four
Scan Conversion
Overview of Graphics System
Scan Conversion/Rasterization:
2D Drawing & 3D Objects made of graphics primitives
Points, lines, circles, & filled polygons
Lines, circles, etc. exist in the continuous space – mathematically
Converting from continuous space to discrete space
Graphics program converts geometrically defined objects to a
set of pixels in the discrete (image) space
Step 2:
Find the number of steps or points in from the starting point to the
ending coordinates.
if (abs (Δx) > abs(Δy)):
Steps = abs(Δx)
else:
Steps = abs(Δy)
Scan Conversion - Line
DDA (Digital Differential Analyzer) Algorithm: (Steps)
Step 3:
Calculate the next point (xi+1 , yi+1) using (xi , yi)
Step 4:
if (end point is not reached ):
Go to step 3 and repeat
Else:
i.e. number of points generated equals the number of
steps(Terminate)
Scan Conversion - Line
DDA (Digital Differential Analyzer) Algorithm: Examples
Calculate the points between the starting point (5, 6) and ending point (8, 12)
Step 1: Δx = 8 – 5 = 3 ; Δy = 12 – 6 = 6 ; m = Δy / Δx = 6 / 3 = 2
Example 3: Calculate the points between the starting point (1, 7) and
ending point (11, 17).
Example 3: between (4,8),(8,10)
Example 3: between (4,6),(7,9)
Scan Conversion - Line
DDA (Digital Differential Analyzer) Algorithm:
Advantages Disadvantages
5
(xk+1, yk+1)
4
(xk, yk)
3
(xk+1, yk)
2 3 4 5
Scan Conversion - Line
Bresenham's Line Algorithm:
Step 3: Calculate Pi+1 & (Xi+1, Yk+1) based on Pi & (Xi, Yi)
Here we need to consider the current value of the parameter for computation
Step 4: Repeat Step 3 until reaching end point number of iteration equals
ΔX-1
Scan Conversion - Line
Bresenham's Line Algorithm: Examples
Calculate the points between the starting coordinates (9, 18) and ending
coordinates (14, 22).
Advantages Disadvantages
For the sake of calculating y from x the above equation can be rewritten:
Scan Conversion - Circle
Properties of a Circle:
Reduce computations by considering the symmetry of circles.
Determine the curve positions in the first quadrant, generate the circle
section in the second quadrant of the xy plane by noting that the two
circle sections are symmetric with respect to the y axis.
And circle sections in the third and fourth quadrants can be obtained
from sections in the first and second quadrants by considering symmetry
about the x axis.
We can take this one step further and note that there is also symmetry
between octants.
Circle sections in adjacent octants within one quadrant are symmetric
with respect to the 45 line dividing the two octants.
Scan Conversion - Circle
Properties of a Circle:
Scan Conversion - Circle
Midpoint Circle Algorithm:
Along a circle section from x = 0 to x = y in the 1st quadrant, the slope (m)
of the curve varies from 0 to -1.0
i.e. we can take unit steps in the +ve x direction over the octant & use
decision parameter to determine which 2 possible positions is vertically
closer to the circle path
or
The idea in this approach is to test the halfway position between two
pixels to determine if this midpoint is inside or outside the circle
boundary.
This method is more easily applied to other conics; and for an integer
circle radius, the midpoint approach generates the same pixel
positions as the Bresenham’s circle algorithm.
Scan Conversion - Circle
Midpoint Circle Algorithm: an incremental algorithm
For a given radius, r and screen center position (xc,yc) , we can set up
our algorithm to calculate pixel positions around a circle path centered at
the coordinate origin (0,0)
Use eight-way symmetry and calculate the points for the top right
eighth of a circle, and then use symmetry to get the rest of the points
Assume that we have just plotted point (xk, yk). The next point is a
choice between (xk+1, yk) and (xk+1, yk-1)
Choose the point that is nearest to the actual circle So how do we make
this choice?
Scan Conversion - Circle
(xk, yk) (xk+1, yk)
(xk+1, yk-1)
Scan Conversion - Circle
Midpoint Circle Algorithm: Given the center and radius of a circle
Step 1: Assign the starting point coordinates (X0, Y0) as-
X0 = 0
Y0 = R
Step 2:Calculate the value of initial decision parameter P0 as-
P0 = 1 – R
Step 3: Find the next point using the parameter Pk
Step 4: If the given center point (Xc, Yc) is not (0, 0), then do the following
and plot the point
Xplot = Xi + Xc
Yplot = Yi + Yc
Step 5: Keep repeating Step-03 and Step-04 until Xplot >= Yplot
To find the points for other seven octants, follow the eight symmetry
property of circle.
Scan Conversion - Circle
Midpoint Circle Algorithm: Example
Given the center point coordinates (0, 0) and radius as 10, generate all the points
to form a circle.
Step-01:
Assign the starting point coordinates (X0, Y0) as-
X0 = 0
Y0 = R = 10
Step-02: Calculate the value of initial decision parameter P0 as-
P0 = 1 – R
P0 = 1 – 10
P0 = -9
Scan Conversion - Curves
Midpoint Circle Algorithm: Example
Step-03:
As Pinitial < 0, so case-01 is satisfied.
Thus,
Xk+1 = Xk + 1 = 0 + 1 = 1
Yk+1 = Yk = 10
Pk+1 = Pk + 2 x Xk+1 + 1 = -9 + (2 x 1) + 1 = -6
Step-04:
This step is not applicable here as the given centre point coordinates is (0, 0).
Step-05:
Step-03 is executed similarly until Xk+1 >= Yk+1 as follows-
Scan Conversion - Curves
Midpoint Circle Algorithm: Example
(-x,y) (x,y)
ry
rx
(-x,-y) (x,-y)
Scan Conversion - Rectangle
Scan Converting a Rectangle:
A rectangle whose sides are parallel to the coordinate axes may be
constructed if the locations of two vertices are known
lines would be drawn as follows: line (x1,y1) to (xl,y2), line (xl,y2) to {x1,y2}
line (x2,y2) to (x2,y1), and line (x2,y1) to (x1,y1).
X1,y1
X2,y1
X2,y2
X1,y2
Example
• Draw rectangle with (x1,y1)=(2,6) and (x2,y2)=(8,2)
• Find (X1,y2)=?
• Find (x2,y1)=?
Filling Polygons
Fill area primitives:
Fill area/Filled area: is an area that is filled with some solid color or
pattern.
Application
For the present, assume that all fill areas are to be displayed with a
specified solid color.
Filling Polygons
Character Generation
Bitmapped Fonts:
Can still generate different size and styles from a single bitmap but the
results are poor quality because bitmap descriptions do not scale well.
Contd…
Two ways of representing characters:
Bitmap (Raster)
00111000
01101100
11000110
11000110
11111110
11000110
11000110
00000000
Character Generation
Bitmapped Fonts:
Character Generation
Outline Fonts
Slow because they must be scan converted into the frame buffer
Contd…
Stroke(outline)
Defined using line/curve primitives
Each character represented (stored) as a series of
line segments
Takes longer time draw than bitmap fonts
we can change the font, colour, and also line
width and line style
width of these lines can be changed using
glLineWidth
style using
glLineStipple
Character Generation
Bitmapped are faster to draw than outline fonts (simple to define and
display), needs more space (font cache)