Chapter 2-Computer Graphics Output Primitives
Chapter 2-Computer Graphics Output Primitives
Computer Graphics
Unit-2
Graphics Primitives
Similarly
for ∆x = -1: we obtain
for ∆y = -1: we obtain
Unit: 2 Graphics Primitives 10 Darshan Institute of Engineering & Technology
Procedure for DDA line algorithm.
Void lineDDA (int xa, int ya, int xb, int yb)
{
int dx = xb – xa, dy = yb – ya, steps, k;
float xincrement, yincrement, x = xa, y = ya;
if (abs(dx)>abs(dy))
{
Steps = abs (dx);
}
else
{
Steps = abs (dy);
}
xincrement = dx/(float) steps;
yincrement = dy/(float) steps;
candidate pixel
[Put ]
Decision parameter
[where ]
[where depending on selection of previous pixel]
[Put ]
[Substitute ]
[Substitute ]
[Initial decision parameter with all terms are constant]
Where is the width of the line and value for partition with is
computed using integer division.
Where
With
Center
r
Radius
(-3, 4) (3, 4)
(-Y, X) (Y, X)
(-4, 3) (4, 3)
(-X, Y) (X, Y)
45 𝑂
(-4, -3) (4, -3)
(-X, -Y) (X, -Y)
yk+1 Candidate
Pixel
xk xk+1 xk+2
If , midpoint is inside the circle and the pixel on the scan line is
closer to circle boundary.
Otherwise midpoint is outside or on the boundary and we select
the scan line .
If we select .
Now put .
Where, &.
4. Determine symmetry points in the other seven octants.
5. Move each calculated pixel position onto the circular path centered on and
plot the coordinate values:
,
6. Repeat steps 3 through 5 until.
Example Midpoint Circle
Algorithm
Example: Draw circle with radius , and center of circle is (Only one
octant to )
First we find pixel position for octant to for center
0 -9 (1, 10)
𝑝(𝑥, 𝑦)
𝑑1
𝑑2
𝑓1 𝑓2
X-axis
Y-axis
𝑟𝑦 𝑟𝑥
(𝑥 𝑐 , 𝑦 𝑐 )
Unit: 2 Graphics Primitives 56 Darshan Institute of Engineering & Technology
Properties of Ellipse-
Symmetry
Symmetry property further reduced computations.
An ellipse in standard position is symmetric between quadrant.
(− 2 , 4) (2 , 4 )
(− 𝑥 , 𝑦 ) (𝑥 , 𝑦 )
𝑟𝑦
𝑟𝑥
(𝑥 𝑐 , 𝑦 𝑐 )
(− 𝑥 ,− 𝑦 ) (𝑥 , − 𝑦 )
(− 2 ,− 4) (2 , − 4)
yk Midpoint
yk-1 Candidate
xk xk + xk+2
Pixel
If, the midpoint is inside the ellipse and the pixel on scan line is
closer to ellipse boundary
Otherwise the midpoint is outside or on the ellipse boundary and
we select the pixel .
ry2x2+rx2y2-rx2ry2=0
between horizontal pixels at each step.
yk Midpoint
yk-1
Candidate
Pixel
xk xk+1 xk+2
For this region, the decision parameter is evaluated as follows.
With
,
And continue until
Contd.
4. Calculate the initial value of the decision parameter in region 2 using the last
point calculated in region 1 as
7. Move each calculated pixel position onto the elliptical path centered on and
plot the coordinate values:
,
Calculation stop
when
Calculation stop
when
Calculation stop
when
Calculation stop
when
Calculation stop
when
Calculation stop
when
Calculation stop
when
Calculation stop
when
Calculation stop
when
Scan line
Scan line
Scan line
Scan line
Counter=2
Counter=3
Counter=4
Counter=5
Counter=6
Counter=1
Counter=0
𝑦0
𝑥0
Unit: 2 Graphics Primitives 95 Darshan Institute of Engineering & Technology
Use of Sorted Edge table in Scan-Line Polygon
Fill Algorithm
To efficiently perform a polygon fill, we can first store the polygon
boundary in a sorted edge table.
It contains all the information necessary to process the scan lines
efficiently.
We use bucket sort to store the edge sorted on the smallest value
of each edge in the correct scan line positions.
Only the non-horizontal edges are entered into the sorted edge
table.
1 2
𝑟 𝑝
1
𝑞
Unit: 2 Graphics Primitives 99 Darshan Institute of Engineering & Technology
Nonzero Winding Number
Rule
This method counts the number of times the polygon edges wind
around a particular point in the counterclockwise direction.
This count is called the winding number.
We apply this rule by initializing winding number with 0.
Then draw a line for any point to distant point beyond the
coordinate extents of the object.
Boundary of Screen
Winding number=0
-1 -1
Winding number=+1-1=0
number=0
number=-1
𝑟 𝑝
+1
𝑞
Unit: 2 Graphics Primitives 101 Darshan Institute of Engineering & Technology
Comparison between Odd Even Rule and
Nonzero Winding Rule
For standard polygons and simple object both rule gives same
result but for more complicated shape both rule gives different
result.
Seed
3
2
(a) (b)
1 2 1 3
1 1
5 6 5
6
(c) 4 5 (d) 4 5
1 4 1 4
1 1
B
curve section and straight line as combine
assembly.
To display the character we need to fill interior
region of the character.
This method requires less storage since each
variation does not required a distinct font cache.
We can produce boldface, italic, or different
sizes by manipulating the curve definitions for
the character outlines.
But this will take more time to process the
outline fonts, because they must be scan
converted into the frame buffer.
Unit: 2 Graphics Primitives 115 Darshan Institute of Engineering & Technology
Stroke Method
• It uses small line segments to generate
a character.
• The small series of line segments are
drawn like a stroke of a pen to form a
character.
• We can generate our own stroke method by calling line
drawing algorithm.
• Here it is necessary to decide which line segments are
needs for each character and then draw that line to
display character.
• It support scaling by changing length of line segment.
2 Dashed
3 Dotted
4 Dotdash
255
If we use more then two color say three at that time equation
becomes as follow: