Computer Graphics (CSE 4103)
Computer Graphics (CSE 4103)
University of Dhaka
Lecture 7
Basic Raster Graphics Algorithm for
Drawing 2D Primitives
p s
p s
• Four cases:
1. s inside plane and p inside plane
• Add p to output
Before Clipping • Note: s has already been
added
2. s inside plane and p outside plane
• Find intersection point i
• Add i to output
3. s outside plane and p outside plane
• Add nothing
4. s outside plane and p inside plane
• Find intersection point i
• Add i to output, followed
by p
After Clipping
Sutherland-Hodgman Polygon Clipping
Algorithm.. Another Example
s2 s3
E1
s4
s5 • Four cases:
s1 1. s inside plane and p inside plane
• Add p to output
s2 s3 • Note: s has already been
added
E1 2. s inside plane and p outside plane
i1 i2 • Find intersection point i
• Add i to output
3. s outside plane and p outside plane
s4 • Add nothing
4. s outside plane and p inside plane
s5 • Find intersection point i
s1 s • Add i to output, followed
2 s3 by p
i1 i2
s4
s5
s1
Sutherland-Hodgman Polygon Clipping
i
Algorithm.. Another Example
2 i3
i4
i5
i1
• Four cases:
1. s inside plane and p inside plane
i2 i3 • Add p to output
j1 • Note: s has already been
j2 added
2. s inside plane and p outside plane
i4
j3 • Find intersection point i
• Add i to output
i5 3. s outside plane and p outside plane
i1 i6 • Add nothing
4. s outside plane and p inside plane
• Find intersection point i
• Add i to output, followed
by p
j1 i3
j2
i4
j3
i5
i6
Sutherland-Hodgman Polygon Clipping
Algorithm.. Another Example
• Four cases:
1. s inside plane and p inside plane
• Add p to output
j1 • Note: s has already been
j2 added
2. s inside plane and p outside plane
j3 • Find intersection point i
i4 j4 • Add i to output
3. s outside plane and p outside plane
j6 j5 • Add nothing
4. s outside plane and p inside plane
• Find intersection point i
• Add i to output, followed
by p
Sutherland-Hodgman Polygon Clipping
Algorithm..
• Four cases:
1. s inside plane and p inside plane
• Add p to output
• Note: s has already been
added
2. s inside plane and p outside plane
• Find intersection point i
• Add i to output
3. s outside plane and p outside plane
• Add nothing
4. s outside plane and p inside plane
• Find intersection point i
• Add i to output, followed
by p
Sutherland-Hodgman Polygon Clipping
Algorithm..
• Four cases:
1. s inside plane and p inside plane
• Add p to output
• Note: s has already been
added
2. s inside plane and p outside plane
• Find intersection point i
• Add i to output
3. s outside plane and p outside plane
• Add nothing
4. s outside plane and p inside plane
• Find intersection point i
• Add i to output, followed
by p
Polygon Filling (Polyfill)
Polygon Filling (Polyfill)..
3. c.d We can consider odd-parity concept to fill the line segment which is inside the
polygon (initially, parity bit is 0, when an intersecting point is occurred, parity is
changed to 1, and then filling is performed before getting a new intersecting point.
Once another intersecting point is occurred, parity is converted to even and no filling is
performed until a new intersecting point is obtained.
Polygon Filling (Polyfill)..
Basic Algorithm (without exception handling)
1. Find the minimum enclosed rectangle
2. Calculate number of scanlines (Ymax-Ymin +1)
3. For each scanline Do
a. Obtain intersection points of scanline with polygon edges
b. Sort intersections from left to right
c. For pairs of intersections from the list
d. Fill within pairs
e. Intersections points are updated for each scanline
3. c.d We can consider odd-parity concept to fill the line segment which is inside the
polygon (initially, parity bit is 0, when an intersecting point is occurred, parity is
changed to 1, and then filling is performed before getting a new intersecting point.
Once another intersecting point is occurred, parity is converted to even and no filling is
performed until a new intersecting point is obtained.
Polygon Filling (Polyfill)..
Normal Case
Problematic
Polygon Filling (Polyfill).. intersection
point
Special Case-1
Problem Solution
Number of Add an extra
intersecting points is intersection point
odd which is the same
where two polygon
edges are meeting
Problematic
intersection
point
Special Case-2
Problem Solution
Number of No need to add any
intersecting points is extra intersecting
even, but one point
intersecting point is
the vertex itself
Polygon Filling (Polyfill)..
Differentiating Special Case-1 and Special Case-2
If the intersecting point is a vertex and two sides of that vertex are in same
side, must add that point again in the list of intersecting points
If the intersecting point is a vertex and two sides of that vertex are in two
sides, don’t add that point again in the list of intersecting points
Thank you