0% found this document useful (0 votes)
5 views6 pages

Akarshan Nigam

The document discusses polygon filling and line clipping techniques in computer graphics, detailing algorithms such as the Scanline, Boundary Fill, Flood Fill, Cohen-Sutherland, Liang-Barsky, and Sutherland-Hodgman algorithms. It explains Cyrus-Beck's algorithm for clipping lines against an arbitrarily oriented window and provides examples for both the Liang-Barsky algorithm and polygon clipping methods. The importance of these techniques in applications like CAD, gaming, and computer vision is also highlighted.

Uploaded by

Abhishek Anand
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)
5 views6 pages

Akarshan Nigam

The document discusses polygon filling and line clipping techniques in computer graphics, detailing algorithms such as the Scanline, Boundary Fill, Flood Fill, Cohen-Sutherland, Liang-Barsky, and Sutherland-Hodgman algorithms. It explains Cyrus-Beck's algorithm for clipping lines against an arbitrarily oriented window and provides examples for both the Liang-Barsky algorithm and polygon clipping methods. The importance of these techniques in applications like CAD, gaming, and computer vision is also highlighted.

Uploaded by

Abhishek Anand
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/ 6

Akarshan Nigam 500095566 B.

Tech(AIML)

Assignment
Q1. Write a short note on Filling Polygons Clipping Lines.
A1. Filling polygons is the process of coloring the interior of a
polygon with a specified color. This is often used to create solid
shapes or to color in 2D shapes. There are various algorithms for
filling polygons such as the Scanline Algorithm, Boundary Fill
Algorithm, and Flood Fill Algorithm.
Clipping Lines, on the other hand, is the process of removing the
parts of lines or shapes that lie outside a specified area, known as
the clipping region. Clipping is often used to limit the rendering of
objects to a certain area, such as the viewport of a graphics window.
There are several algorithms for clipping lines such as the Cohen-
Sutherland algorithm, Liang-Barsky algorithm, and Sutherland-
Hodgman algorithm.

Q2. Explain Cyrus Beck's algorithm with an example.


A2. Cyrus-Beck algorithm is a line clipping algorithm used to clip
lines against an arbitrarily oriented clipping window. This algorithm
is based on the idea of projecting the line onto the normal vectors of
the clipping edges and then finding the intersection points of the
projected line with the edges.
The algorithm works as follows:
1. Define a clipping window as a polygon with n edges, each
represented by a pair of vertices (x_i, y_i) and (x_i+1, y_i+1)
for i = 0 to n-1. The edges are assumed to be connected in a
closed loop, with the last vertex (x_n, y_n) connecting to the
first vertex (x_0, y_0).
2. Define a line segment to be clipped, with endpoints (x_0, y_0)
and (x_1, y_1).
3. Calculate the direction vector of the line segment, d = (x_1 -
x_0, y_1 - y_0).
4. For each edge of the clipping window, calculate the normal
vector n = (y_i+1 - y_i, -(x_i+1 - x_i)). The dot product of the
direction vector and the normal vector gives the projection of
the line segment onto the edge, t_i = (n . (x_0, y_0) - n . (x_i,
y_i)) / (n . d).
5. Calculate the maximum value of t (t_max) from the values of t_i
that correspond to the edges that intersect with the line
segment. Similarly, calculate the minimum value of t (t_min).
6. If t_max < t_min, the line segment is outside the clipping
window and can be discarded.
7. Otherwise, calculate the intersection points of the line segment
with the clipping window by using the values of t_min and
t_max. The intersection points are (x_0 + t_min * (x_1 - x_0),
y_0 + t_min * (y_1 - y_0)) and (x_0 + t_max * (x_1 - x_0), y_0
+ t_max * (y_1 - y_0)).
Here is an example:
Consider a clipping window with four edges defined by the vertices
(1, 1), (3, 4), (4, 2), and (2, 0). We want to clip a line segment with
endpoints (0, 2) and (5, 3) against this window.
8. The clipping window has four edges: (1, 1)-(3, 4), (3, 4)-(4, 2),
(4, 2)-(2, 0), and (2, 0)-(1, 1).
9. The line segment to be clipped has endpoints (0, 2) and (5, 3).
10. The direction vector of the line segment is d = (5 - 0, 3 -
2) = (5, 1).
11. For each edge of the clipping window, calculate the
normal vector and the value of t_i:
• For the edge (1, 1)-(3, 4), the normal vector is n = (3 - 1, -(3 -
1)) = (2, -2). The dot product of d and n is 5 * 2 + 1 * (-2) = 8,
and the dot product of n and (0, 2) is 2 * 0 + (-2) * 2 = -4.
Therefore, t_i = (-4 - 2) / 8 = -3

Q3. Explain the Liang-Barsky algorithm with an example.


A3. Liang-Barsky algorithm is a line clipping algorithm that works by
calculating the intersection points of a line segment with a clipping
window, if any. This algorithm uses parameterization of the line
segment to calculate the intersection points, which makes it efficient
and easy to implement.
The algorithm works as follows:
12. Define a clipping window with edges represented by four
values: xmin, xmax, ymin, ymax.
13. Define a line segment with endpoints (x0, y0) and (x1, y1).
14. Calculate the parameter values of the line segment for
each of the four edges of the clipping window using the
following equations:
dx = x1 - x0 dy = y1 - y0 p1 = -dx p2 = dx p3 = -dy p4 = dy q1 =
x0 - xmin q2 = xmax - x0 q3 = y0 - ymin q4 = ymax - y0
15. Calculate the intersection points using the following
equations:
r1 = q1 / p1 r2 = q2 / p2 r3 = q3 / p3 r4 = q4 / p4
16. Determine the values of the parameter t at which the line
enters and leaves the clipping window:
t1 = max(0, max(min(r1, r2), min(r3, r4))) t2 = min(1, min(max(r1,
r2), max(r3, r4)))
17. If t1 > t2, the line segment lies entirely outside the
clipping window and can be discarded. Otherwise, calculate the
coordinates of the intersection points:
x0' = x0 + t1 * dx y0' = y0 + t1 * dy x1' = x0 + t2 * dx y1' = y0 +
t2 * dy
Here is an example:
Consider a clipping window with xmin=2, xmax=6, ymin=3, ymax=7.
We want to clip a line segment with endpoints (1, 5) and (8, 2)
against this window.
18. The clipping window has xmin=2, xmax=6, ymin=3,
ymax=7.
19. The line segment to be clipped has endpoints (1, 5) and (8,
2).
20. Calculate the parameter values for each of the four edges
of the clipping window:
dx = 8 - 1 = 7 dy = 2 - 5 = -3 p1 = -7 p2 = 7 p3 = 3 p4 = -3 q1 = 1
- 2 = -1 q2 = 6 - 1 = 5 q3 = 5 - 3 = 2 q4 = 7 - 5 = 2
21. Calculate the intersection points:
r1 = (-1) / (-7) = 1/7 r2 = 5 / 7 r3 = 2 / 3 r4 = 2 / (-3) = -2/3
22. Determine the values of the parameter t:
t1 = max(0, max(min(1/7, 5/7), min(2/3, -2/3))) = 1/7 t2 = min(1,
min(max(1/7, 5/7), max(2/3, -2/3))) = 5/7
23. Calculate the coordinates of the intersection points:
x0' = 1 + (1/7) * 7 = 2

Q4. Elaborate on “Clipping Polygons”.


A4. Clipping polygons is the process of removing portions of a
polygon that lie outside a specified boundary, also known as a
clipping window. The goal of polygon clipping is to find the
intersection between the original polygon and the clipping window,
resulting in a new polygon that lies entirely within the boundary.
Polygon clipping is commonly used in computer graphics and
computer-aided design (CAD) to display only the parts of an object
that are visible within the window or viewport. It is also used in
computer vision applications, such as image segmentation, where the
objective is to extract the part of an image that corresponds to a
certain object or region of interest.
There are several algorithms for polygon clipping, including the
Sutherland-Hodgman algorithm, Weiler-Atherton algorithm, and the
Greiner-Hormann algorithm. These algorithms work by iteratively
clipping the polygon against each edge of the clipping window until a
new polygon is formed that lies entirely within the boundary.
The Sutherland-Hodgman algorithm is a simple algorithm for polygon
clipping that works by clipping the polygon against each edge of the
clipping window in turn. The algorithm works as follows:
24. Begin with the original polygon.
25. Clip the polygon against the left edge of the clipping
window, retaining only those portions of the polygon that lie to
the right of the edge.
26. Clip the resulting polygon against the right edge of the
clipping window, retaining only those portions of the polygon
that lie to the left of the edge.
27. Clip the resulting polygon against the bottom edge of the
clipping window, retaining only those portions of the polygon
that lie above the edge.
28. Clip the resulting polygon against the top edge of the
clipping window, retaining only those portions of the polygon
that lie below the edge.
29. The resulting polygon is the clipped polygon.
Polygon clipping is a fundamental operation in computer graphics and
computer vision, and it is used extensively in various applications,
including gaming, animation, and simulation.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy