Unit 2 Output Primitives
Unit 2 Output Primitives
Output Primitives
x
Point Drawing:
Converting a single coordinate position furnished by
an application program into appropriate operation for
the output device in use.
In raster system:
Black-white: setting the bit value corresponding to a
specified screen position within the frame buffer to 1.
RGB: loading the frame buffer with the color codes for the
intensities that are to be displayed at the screen pixel
positions.
Line Drawing Algorithms
y2
y1
x1 x2
Line Drawing:
A straight line is specified by two endpoint
positions.
Line drawing is done by:
Calculating intermediate positions between the
endpoints.
Directing the output device to fill in the calculated
positions as in the case of plotting single points.
Line Drawing:
Plotted positions may be only approximations to the
actual line positions between endpoints.
A computed position (10.48, 20.51) is converted to pixel
(10,21).
This rounding causes the lines to be displayed with a stairstep
appearance.
Stairsteps are noticeable in low resolution systems, it can be
improved by:
Displaying lines on high resolution systems.
Adjusting intensities along line path.
Line Drawing:
The Cartesian intercept equation for a straight line:
y= m. x +b
.Where m is the line slop and b is y intercept
For line segment starting in (x1,y1) and ending in (x2,y2), the slop
is:
m= (y1-y2)/(x1-x2)
b= y1- m.x1
For any given x interval x, we can compute the corresponding y interval
y:
y= m .x
Or x interval x from a given y:
x= y/m
Line Drawing:
Sampling along x axis
On raster systems, lines are plotted
Y2
with pixels, and step sizes in the
horizontal and vertical directions are
constrained by pixel separations. y1
X1 x2
Scan conversion process samples a
line at discrete positions and determine Sampling along y axis
the nearest pixel to the line at each Y2
sampled position.
y1
X1 x2
Line Drawing Algorithms:
Digital Differential Analyzer (DDA):
Samples the line at unit intervals in one coordinate
and determine corresponding integer values nearest
.the line path for the other coordinate
Bresenhams Line Algorithm:
Scan converts lines using only incremental integer
.calculations
Line Drawing Algorithms:
DDA
A scan-conversion line algorithm based on calculating either
y or x using line points calculating equations.
In each case, choosing the sample axis depends on the slop
value.
The unit step for the selected axis is 1.
The other axis is calculated depending on the first axis and
the slop m.
The next slides will show the different cases of the slop:
Line Drawing Algorithms:
DDA
Case 1:the slop is Positive and less than 1
Sample at unit x interval (x=1) and compute each successive
y value as :
y k+1= yk+ m
K takes integer values starting from 1,at the first point, and
increasing by 1 on each step until reaching the final endpoint.
The calculated y must be rounded to the nearest integer.
Example:
Describe the line segment which starts at (3,3) and ends at
.(23,7)
Lines Drawing Algorithms: DDA
24
23
22
21
m= (7-3)/(23-3) 20
=4/20 19
18
=0.2 17
16
15
x=1 14
13
y=0.2 12
11
10
9
8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Lines Drawing Algorithms: DDA
x y actual point pixel position 24
23
3 3 (3,3) (3,3) 22
4 3.2 (4,3.2) (4,3) 21
5 3.4 (5,3.4) (5,3) 20
6 3.6 (6,3.6) (6,4) 19
18
7 3.8 (7,3.8) (7,4) 17
8 4 (8,4) (8,4) 16
9 4.2 (9,4.2) (9,4) 15
10 4.4 (10,4.4) (10,4) 14
13
11 4.6 (11,4.6) (11,5) 12
12 4.8 (12,4.8) (12,5) 11
13 5 (13,5) (13,5) 10
9
14 5.2 (14,5.2) (14,5) 8
15 5.4 (15,5.4) (15,5) 7
16 5.6 (16,5.6) (16,6) 6
17 5.8 (17,5.8) (17,6) 5
4
.. .. .. .. 3
.. .. .. .. 2
22 6.8 (22,6.8) (22,7) 1
0
23 7 (23,7) (23,7)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Line Drawing Algorithms:
DDA
Case 2:the slop is Positive and greater than 1
Sample at unit y interval (y=1) and compute each successive
y value as :
x k+1= xk+ (1/m)
K takes integer values starting from 1,at the first point, and
increasing by 1 on each step until reaching the final endpoint.
The calculated x must be rounded to the nearest integer.
Example:
Describe the line segment which starts at (3,3) and ends at
.(7,23)
Line Drawing Algorithms: DDA
24
23
22
m= (23-3)/(7-3) 21
20
= 20/4 19
=5 18
17
16
15
x =1/m 14
=1/5 13
12
=0.2 11
10
9
y =1 8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Line Drawing Algorithms: DDA
y x actual point pixel position 24
23
3 3 (3,3) (3,3) 22
4 3.2 (3.2,4) (3,4) 21
5 3.4 (3.4,5) (3,5) 20
6 3.6 (3.6,6) (4,6) 19
18
7 3.8 (3.8,7) (4,7) 17
8 4 (4,8) (4,8) 16
9 4.2 (4.2,9) (4,9) 15
10 4.4 (4.4,10) (4,10) 14
13
11 4.6 (4.6,11) (5,11) 12
12 4.8 (4.8,12) (5,12) 11
13 5 (5,13) (5,13) 10
9
14 5.2 (5.2,14) (5,14) 8
15 5.4 (5.4,15) (5,15) 7
16 5.6 (5.6,16) (6,16) 6
17 5.8 (5.8,17) (6,17) 5
4
.. .. .. .. 3
.. .. .. .. 2
22 6.8 (6.8,22) (7,22) 1
0
23 7 (7,23) (7,23)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Line Drawing Algorithms:
DDA
Case 3:the slop is negative and its absolute value is less than 1
Follow the same way in case 1.
Case 4:the slop is negative and its absolute value is greater than 1
Follow the same way in case 2.
In the previous 4 cases, we start from the left to the right. If the
state is reversed then:
If the absolute slop is less than 1, set x=-1 and
y k+1= yk - m
If the absolute slop is greater than 1, set y=-1 and
x k+1= xk - (1/m)
Line Drawing Algorithms:
DDA properties
A faster method for calculating pixel positions than the direct
use: y= m . x +b.
Uses x or y to eliminate the multiplication in the above
equation.
Rounding successive additions of the floating-point
increment can cause the calculated pixel positions to drift
away from the true line path for long line segment.
Rounding and floating-point arithmetic are time-consuming
operations.
Line Drawing Algorithms:
Standard Algorithm
Polar Algorithm
Symmetry Algorithm
Mid-point Algorithm (xc, yc )
r (x, y)
Standard Algorithm:
x,y
r
Symmetry Algorithm:
Reduces computations by considering the
symmetry of circles in the eight octants in the xy
plane.
Generates all pixel positions
around a circle by calculating
only the points within the
sector from x = 0 to x = y.
Mid-point Algorithm:
Samples at unit intervals and uses decision parameter to
determine the closest pixel position to the specified circle path at
each step.
Along the circle section from x = 0 to x = y in the first quadrant, the
slope of the curve varies from 0 to -1. Therefore, we can take unit
steps in the positive x direction over this octant and use a decision
parameter to determine which of the two possible y positions is
closer to the circle path at each step. Positions in the other seven
octants are then obtained by symmetry.
Mid-point Algorithm:
To apply mid-point method, we define a circle function:
we calculate positions in the first octant only , beginning with x=0 and
ending when x=y
ry
F2 rx F1
d2 d1
P=(x,y)
Ellipse Properties:
An elongated circle.
A set of points having an equal sum distances from two fixed
positions (foci F1,F2).
d1+d2=constant
The major axis is the straight line segment extending from one
side of the ellipse to the other through the foci.
The minor axis spans the shorter dimension of the ellipse,
bisecting the major axis at the halfway position (ellipse center)
between the two foci.
The two foci and point coordinates on the circumference are
enough information to plot an ellipse with arbitrary orientation.
Ellipse Properties:
The equation of the ellipse can be written in terms of the
ellipse center coordinates and parameters rx, and ry, as:
Scan line
Filled Area Primitives:
Scan line
Filled Area Primitives:
Scan line
Inside-Outside Tests:
Odd-even (odd parity or even odd) rule:
Drawing a line from any position P to a distant point
outside the coordinate extents of the object.
Counting the number of edge crossings along the line.
If the number of polygon edges crossed by this line is
odd, then P is an interior point, otherwise it is an
exterior point.
The line chosen must not intersect the polygon
vertices.
Inside-Outside Tests:
Non-zero winding number rule:
Counts the number of times the polygon edges wind around a
particular point in the counterclockwise direction, which is called
winding number.
Interior points of a two-dimensional object are defined to be those
that have a nonzero value for the winding number.
Counting method:
Start winding number with 0.
Imagine a line passing across the object and not intersect vertices.
Add 1 to winding number when the line is crossed by an edge from right to left.
Subtract 1 from winding number when the line is crossed by an edge from left to
right.
To determine the direction use either cross product or dot product.
Inside-Outside Tests:
Scan-Line Fill of Curved Boundary Areas :