0% found this document useful (0 votes)
30 views10 pages

CG Unit 2 Sol

The document discusses different types of polygons and algorithms used for filling polygons, including seed fill, flood fill, scan line, and Cohen-Sutherland and Sutherland-Hodgeman clipping algorithms. Key aspects covered include the definitions of regular, irregular, convex, concise polygons and how seed fill, flood fill, and scan line algorithms work in steps to fill polygons. Polygon clipping algorithms are also explained with examples.

Uploaded by

ajitkolpuke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views10 pages

CG Unit 2 Sol

The document discusses different types of polygons and algorithms used for filling polygons, including seed fill, flood fill, scan line, and Cohen-Sutherland and Sutherland-Hodgeman clipping algorithms. Key aspects covered include the definitions of regular, irregular, convex, concise polygons and how seed fill, flood fill, and scan line algorithms work in steps to fill polygons. Polygon clipping algorithms are also explained with examples.

Uploaded by

ajitkolpuke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Q.1 What is Polygon?

Explain different types of polygons


ANS : A polygon is a closed 2D shape that is made up of a finite number of straight line
segments. In computer graphics, polygons, especially triangles, are fundamental in representing
surface shapes and details, due to their simplicity and ease of calculation.

Types of Polygons:

1. Regular Polygon: All sides and angles are equal. Examples include squares, equilateral
triangles, and regular hexagons.

2. Irregular Polygon: Sides and angles are not necessarily equal. For instance, a scalene
triangle.

3. Convex Polygon: All internal angles are less than 180°. A rectangle is an example.

4. Concave Polygon: At least one internal angle is more than 180°. Think of a shape that
appears "dented" inward.

5. Simple Polygon: The sides do not intersect, except at the vertices.

6. Complex Polygon: Sides intersect each other beyond just at the vertices.

Q.2 Explain and compare seed fill and edge fill algorithm for
polygon
ANS:

Seed Fill Algorithm:

Seed Fill, often known as the Flood Fill algorithm, starts from an initial 'seed' point and
proceeds to fill the neighboring regions based on specific criteria. It's similar to filling a region
with color in paint software. There are two common types:

1. Four-Connected Approach: Checks top, bottom, left, and right pixels.

2. Eight-Connected Approach: Checks diagonal pixels in addition to the four primary


directions..

Edge Fill Algorithm:


Edge Fill or Boundary Fill algorithm works by filling pixels until a boundary color is encountered.
Starting from a seed point, this method fills the region but stops when the boundary color is
met.

Comparison:

1. Criterion Basis: While Seed Fill colors a pixel based on its neighbors, Edge Fill colors until it
meets a boundary.

2. Efficiency: Edge Fill can be more efficient if boundary details are known as it directly works
with boundaries rather than assessing neighboring pixels extensively.

3. Implementation: Seed Fill can be simpler to implement, especially for small regions or
basic applications. However, Edge Fill can offer more precision when dealing with complex
shapes with predefined boundaries.

Q.3 Explain the steps in Scan Line Algorithm for filling the
polygon
ANS: The Scan Line Polygon Fill Algorithm is a method to determine and fill the pixels within a
polygon's boundary based on a scan line concept. Here's a concise breakdown of its steps:

1. Edge List Preparation:

- For each side (edge) of the polygon, record the minimum Y (starting Y), maximum Y (ending
Y), the X-coordinate associated with the minimum Y, and the slope inverse (1/m).

2. Sorting:

- Sort the edge table by minimum Y. If two sides have the same minimum Y, sort by the X-
coordinate.

3. Scan Line Process:

- Starting from the minimum Y (lowest scan line that intersects the polygon) to the maximum
Y, perform the following for each scan line:

a. Active Edge Table (AET) Update:


- Move edges from the sorted edge table to the Active Edge Table (AET) whose minimum Y
matches the current scan line.

b. Remove Inactive Edges:

- From the AET, remove edges for which the scan line has passed the maximum Y.

c. Sort AET:

- Order edges based on X-coordinates.

d. Fill Pixels:

- Fill alternate pairs of intersections. If the X-coordinates in the AET are X1, X2, X3, X4 ,...,
then fill pixels between X1 and X2, skip between X2 and X3, fill between X3 and X4, and so on.

e. Update X:

- For each edge in the AET, update the X-coordinate by adding the slope inverse.

f. Move to Next Scan Line:

- Increment the Y value and repeat the process.

Q.4 Explain different methods for testing a pixel inside


polygon
ANS: Methods for Testing a Pixel Inside a Polygon in Computer Graphics:

1. Ray Casting (or Odd-Even Rule):

- Cast a ray from the test point in any direction.

- Count how many times the ray intersects with the polygon edges.

- If count is odd, the point is inside; if even, the point is outside.

2. Winding Number Method:

- Check how many times the polygon winds around the test point.

- If zero, the point is outside; otherwise, it's inside.

3. Point-in-Polygon using Triangle Testing:


- Break the polygon into triangles.

- Test if the point lies inside any of these triangles. If so, it lies inside the polygon.

4. Crossing Number Algorithm:

- Similar to the Ray Casting method but specifically counts upward or downward edge crossings.

- Odd count implies inside, while even count implies outside.

Q.5 Explain the following polygon filling algorithms 1] Seed fill


2] Flood fill
ANS:

1. Seed Fill Algorithm:

Principle: Seed Fill is a recursive method that starts from a 'seed' pixel and colors adjacent
pixels based on specific conditions, essentially filling regions of connectivity.

Working:

 Choose a point inside the polygon as the seed.

 Color the seed pixel.

 Examine neighboring pixels. If they are within the boundary and not already filled,
color them and treat them as new seeds.

 Continue the process until no more pixels can be colored.

Usage: Suitable for irregular and non-uniform shaped polygons. It can be categorized as 4-
connected or 8-connected based on pixel connectivity considered.

2. Flood Fill Algorithm:

Principle: Similar to Seed Fill, but instead of filling until a boundary is met, Flood Fill replaces a
specified interior color (target color) with a new fill color.

Working:

 Start from a seed pixel.


 If the current pixel's color matches the target color, change it to the fill color.

 Recursively apply the flood fill for all adjacent pixels.

 Termination occurs when pixels do not match the target color or have already been
visited.

-Usage: Useful in applications like 'paint bucket' tools in graphic software.

Q.6 Explain Cohen-Sutherland line clipping Algorithm with the


help of suitable example
ANS: The Cohen-Sutherland algorithm is used to clip lines against a rectangular clipping
window. It reduces unnecessary calculations by using a simple bitwise technique.

Steps:

1. Encoding Endpoints: Each endpoint of the line is assigned a 4-bit code (called the outcode)
based on its position relative to the clipping window.

- Bit 1: Above the window

- Bit 2: Below the window

- Bit 3: To the right of the window

- Bit 4: To the left of the window

For a point inside the window, the outcode is 0000.

2. Initial Test: If both outcodes are 0000, the line is inside the window and accepted. If the
bitwise AND of the outcodes is not 0000, the line is completely outside and rejected.

3. Clipping: If not accepted or rejected, find an intersection point of the line with the clipping
boundary (using the outcode of one of the endpoints), and replace that endpoint with the
intersection point. Repeat until the line is either accepted or rejected.

Example:

Consider a line with endpoints A(2, 8) and B(12, 4) and a clipping window with boundaries x=4,
x=10, y=3, and y=7.
- For A(2, 8):

1. Above the window? Yes

2. Below the window? No

3. Right of the window? No

4. Left of the window? Yes

Outcode for A: 1001

- For B(12, 4):

1. Above the window? No

2. Below the window? No

3. Right of the window? Yes

4. Left of the window? No

Outcode for B: 0100

Bitwise AND is not 0000, so the line isn't immediately accepted or rejected.

On processing, the line will intersect the clipping window and a portion of it will be within the
window.

Q.7 Describe Sutherland-Hodgeman polygon clipping


algorithm
ANS: The Sutherland-Hodgeman algorithm clips a polygon against a clipping rectangle. Unlike
line clipping algorithms which clip lines, this algorithm focuses on polygons.

Steps:

1. Initialization: Start with one clipping boundary (e.g., left edge of the clipping rectangle). The
polygon vertices will be processed against this edge first.

2. Processing Each Vertex:

- Take two consecutive vertices of the polygon, ( V_1 ) and ( V_2 ).


- Determine if each vertex is inside or outside the clipping boundary.

3. Possible Cases:

a. Both ( V_1 ) and ( V_2 ) are inside: Add ( V_2 ) to the output list.

b. ( V_1 ) is inside and ( V_2 ) is outside: Find the intersection point ( I ) with the clipping
boundary and add ( I ) to the output list.

c. Both ( V_1 ) and ( V_2 ) are outside: Discard ( V_2 ) (i.e., do nothing).

d. ( V_1 ) is outside and ( V_2 ) is inside: Find the intersection point ( I ) with the clipping
boundary, add ( I ) and then ( V_2 ) to the output list.

4. Iterate: Use the output list from one clipping boundary as the input for the next boundary.
Repeat steps 2-3 for each of the four boundaries of the clipping rectangle.

5. Completion: After all boundaries have been processed, the vertices in the final output list
define the clipped polygon.

Q.8 Explain seed fill algorithm for polygon filling


ANS: The Seed Fill algorithm is a method used to determine and shade the pixels inside a
polygon or any enclosed area. It operates in a manner similar to pouring paint into an area on a
canvas.

Steps:

1. Initialization: Choose a point inside the polygon, termed as the 'seed' point.

2. Pixel Examination: Check the neighboring pixels around the seed to determine if they should
be colored.

3. Filling & Propagation:

- If a neighboring pixel meets the fill criteria (e.g., it's not yet colored or it's not a boundary
pixel), color it.

- Once colored, this new pixel becomes another seed point, leading to a recursive or iterative
process.

4. Termination: The process continues until all contiguous, non-boundary pixels connected to
the initial seed point have been filled.
There are two variations based on how we examine neighbors:

- 4-connected fill: Checks top, bottom, left, and right neighbors.

- 8-connected fill: Also includes diagonal neighbors.

Q.9 Explain Flood fill algorithm for polygon filling


ANS: The Flood Fill algorithm is used to determine and fill an enclosed area with a particular
color, starting from a 'seed' pixel and progressing to all neighboring pixels that share the same
color as the seed.

Steps:

1. Initialization: Choose an initial pixel (the 'seed') within the polygon or region to be filled.

2. Examination: Check the color of the seed pixel and determine the target color to be
replaced.

3. Filling & Expansion:

- Change the seed pixel's color to the desired fill color.

- Examine neighboring pixels. If they match the target color, change their color and treat them
as new seed points.

4. Recursion/Iteration: The process is recursively or iteratively applied to every newly colored


pixel, ensuring all adjacent pixels of the target color are filled.

5. Completion: The algorithm stops when no more neighboring pixels of the target color can be
found.

The method can operate as:

- 4-connected fill: Considers top, bottom, left, and right neighbors.

- 8-connected fill: Also examines diagonal neighbors.

Q.10 Describe Weiler Atherton Polygon clipping algorithm


with help of suitable example.
ANS: The Weiler-Atherton algorithm is a method used for clipping polygons in computer
graphics. Unlike simpler algorithms which handle rectangles and convex polygons, this
algorithm can clip complex, concave polygons as well.

Steps:

1. Initialization: List the vertices of the subject polygon and the clipping window.

2. Intersection Points: Calculate intersection points of the subject polygon with the clipping
window. Add these intersection points to both the subject and clipper lists, maintaining the
order.

3. Classification: Classify each vertex of the subject polygon and the clipping window as either
"inside" or "outside" based on the other polygon.

4. Generate Resultant Polygons:

- Starting from an "inside" vertex of the subject polygon, traverse its vertices in order. If an
intersection point is reached, switch to the clipping window's list and continue until returning to
the starting point. This forms one clipped polygon.

- If more vertices remain, start a new clipped polygon and repeat.

Example:

Imagine a subject polygon shaped like a "U" and a square clipping window where the "U"
straddles the top edge of the square. Thus, part of the "U" is inside the square, and part is
outside.

1. Intersection Points: The two points where the "U" intersects the top edge of the square are
calculated.

2. Classification: The vertices of the "U" above the square are classified as "outside", and those
inside or on the square are "inside".

3. Resultant Polygons: Starting from an "inside" vertex at the bottom of the "U", we trace its
shape. Upon reaching an intersection point at the top of the square, we switch to tracing the
square's perimeter. Once we reach the second intersection point on the square, we switch back
to the "U" and continue until we close the polygon. The result is a polygon that represents the
portion of the "U" inside the square.
Q.11 Write short note on image transformation with example
ANS: Image transformation refers to the process of modifying the appearance of an image in
terms of its position, orientation, or size. There are three primary types of 2D transformations:
translation, rotation, and scaling.

1. Translation: Involves moving an image from one location to another without changing its
orientation or size.

- Example: Shifting an image 10 units to the right and 5 units up would be a translation.
Mathematically, if a point is at (x, y), after translation, it could be at (x+10, y+5).

2. Rotation: Involves turning an image around a specific point, called the pivot or rotation
point.

- Example: Rotating an image 45° about its center would result in each point moving to a new
location while maintaining the same distance from the center.

3. Scaling: Changes the size of an image. It can be uniform (same factor for both height and
width) or non-uniform.

- Example: Scaling an image by a factor of 2 would double its size. If a point is at (x, y), after
uniform scaling, it would be at (2x, 2y).

You might also like