Вы находитесь на странице: 1из 26

Output

Primitives
MUHAMMAD AMMAR SHAIKH
201-S14-006
Output Primitives

Output primitives are the basic geometric structures which facilitate or


describe a scene/picture. Example of these include:
points, lines, curves (circles, conics etc), surfaces, fill colour, character
string etc.
Points:
A point is shown by
illuminating a pixel on the
screen
Lines:

A line segment is completely defined in terms of its two


endpoints.
A line segment is thus defined as:
Line_Seg = { (x1, y1), (x2, y2) }
Lines
A line is produced by y
means of illuminating a set
of intermediary pixels
between the two endpoints.

y2

y1

x1 x2 x
Digital Differential Analyzer

Algorithm is an incremental scan


conversion method.
Based on calculating either x or y
If |m|<1, (x 1)
y mx
y K 1
y m
k
DDA Algorithm
If |m|>1, ( y 1)
y
x
m
1
x x
K 1
m
k

If (x 1)
y mx
y y m
K 1 k
Advantages
DDA algorithm is a faster method for calculating the pixel
positions than the direct use of line equation.
It eliminates multiplication by making use of raster
characteristics.

Disadvantages
DDA algorithm runs slowly because it requires real arithmetic
(floating point operations) and rounding operations
Bresenhams Line Algorithm
A highly efficient incremental
method for scan converting lines.
Using only incremental integer
calculation.
Bresenhams
Algorithm(cont.)
(for |m| < 1.0)
Input the two line end-points, storing the left end-point
in (x0, y0)
Plot the point (x0, y0)
Calculate the constants x, y, 2y, and (2y - 2x)
and get the first value for the decision parameter as:
p0 2y x
At each xk along the line, starting at k = 0, perform the
following test. If pk < 0, the next point to plot is
(xk+1, yk) and: pk 1 pk 2y
Bresenhams Algorithm

Otherwise, the next point to plot is (xk+1, yk+1)


and: pk 1 pk 2y 2x
Repeat step 4 (x) times
Example Draw a line from (20,10) to (30,18)
x = 10
y=8
initial decision parameter has the value p0 = 2 y x =
6 (30,18)
Increment for calculating successive decision parameter
are 2 y = 16, 2 y 2 x) = -4 (20,10)

k pk (xk+1,yk+1) 19
18
0 6 (21,11)
17
1 2 (22,12)
2 -2 (23,12) 16

3 14 (24,13) 15
4 10 (25,14) 14
5 6 (26,15) 13
6 2 (27,16) 12
7 -2 (28,16)
11
8 14 (29,17)
10
9 10 (30,18)
20 21 22 23 24 25 26 27 28 29 30 31 32

Compile by : Engr. Syed Atir Iftikhar


Bresenhams
Algorithm(cont.) 20 , 10
K Pk (X k+1 , Y k+1) Pk + 2 y2 x
0 6 21 , 11 6 + 16 -20 = 2
1 2 22 , 12 2 + 16 20 = -2
2 -2 23 , 12 -2 +16 = 14
3 14 24 , 13 14+ 16 20 = 10
4 10 25 , 14 10 + 16 - 20 = 6
5 6 26 , 15 6 +16 -20 = 2
6 2 27 , 16 2 + 16 20 = -2
7 -2 28 , 16 -2 +16 = 14
8 14 29 , 17 14 + 16 -20 = 10
9 10 30 , 18 10 +16 - 20 = 6

If pk < 0, the next point to plot is (xk+1, yk) and: pk 1 pk 2y


Circle Generating Algorithms

A circle is defined as the set of points that are all at a given


distance r from a center point (xc, yc).
For any circle point (x, y), this distance is
expressed by the Equation
(x xc)2 + (y yc)2 = r 2
We calculate the points by stepping along the x-axis in unit
steps from xc-r to xc+r and calculate y values as
Mid point Circle Algorithm

To apply the midpoint method, we define a circle function:

Any point (x,y) on the boundary of the circle with radius r


satisfies the equation fcircle(x, y)= 0.
Circle Generation Algorithms

We use it to define a decision


parameter
1 1
p f ( x 1, y ) ( x 1) ( y ) r
2 2 2

2 2
i i i i
Example:
To see the mid-point (0 , r)
circle algorithm in action (0 , 10)
lets use it to draw a Pk
circle centred at (0,0 k (xk+1,yk+1) 2xk+1 2yk+1
/Po
0 -9 1 , 10 2 20
10
9 4 20
8
7
1 -6 2 , 10
6
5 2 -1 3 , 10 6 20
4
3
2 3 6 4,9 8 18
1
0
0 1 2 3 4 5 6 7 8 9 10 4 -3 5,9 10 18

5 8 6,8 12 16

5 7,7 14 14
6
Fill Area Algorithms

Fill-Area algorithms are used to fill the interior of a polygonal


shape.
Many algorithms perform fill operations by first identifying
the interior points, given the polygon boundary.
Basic Filling Algorithm
The basic filling algorithm is commonly used in interactive
graphics packages, where the user specifies an interior
point of
the region to be filled.

4-connected pixels
Types of Basic Filling Algorithms

Boundary Fill Algorithm


For filling a region with a single boundary color.
Condition for setting pixels:
Color is not the same as border color
Color is not the same as fill color

Flood Fill Algorithm


For filling a region with multiple boundary colors.
Condition for setting pixels:
Color is same as the old interior color
Character Generation
Two different representation are used
for storing computer fonts:

1.Bitmap font (or bitmapped font)

2.Outline font
Bitmap font
Bitmap font (or bitmapped font):
A simple method for representing the
character shapes in a particular typeface is
to use rectangular grid pattern.
Bitmap font
The character grid only need to be
mapped to a frame buffer position.
Bitmap fonts required more space, because
each variation (size and format) must be
stored in a font cash.

Bold Italic
Outline Font
Graphic primitives such as lines and arcs are
used to define the outline of each character.
Require less storage since variation does not
require a distinct font cash.
Outline Font
We can produce boldface, italic, or
different size by manipulating the curve
definition for the character outlines.

It does take more time to process the


outline fonts, because they must be scan
converted into frame buffer.
Thank You

Вам также может понравиться