I017 CG Lab7
I017 CG Lab7
Outcomes:-
- Student will explore the clipping process can be applied to various geometric
entities such as points, lines, and polygons, and it is fundamental in the rendering
pipeline of computer graphics to handle the visibility of objects within a defined
region of interest.
1
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
1. A convex polygon and a convex clipping area are given. The task is to clip polygon edges
using the Sutherland–Hodgman Algorithm. Input is in the form of vertices of the polygon in
clockwise order. Examples:
Code:
import matplotlib.pyplot as plt
2
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
# Initialize variables
dx = x2 - x1
dy = y2 - y1
t0, t1 = 0.0, 1.0
3
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
else:
t0 = max(t0, t_top)
if t0 > t1:
return None, None
for i in range(len(input_list)):
p1 = input_list[i]
p2 = input_list[(i + 1) % len(input_list)]
if intersection:
output_list.append(intersection)
if p2_clipped:
output_list.append(p2_clipped)
return output_list
return x_min <= x <= x_max and y_min <= y <= y_max
4
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
# Example usage
polygon = [(100, 100), (300, 100), (300, 300), (100, 300)]
clip_rect = [(150, 150), (250, 150), (250, 250), (150, 250)]
Output:
Conclusion: -
1. Use a more efficient data structure: Instead of iterating over each edge of the polygon and the
clipping rectangle separately, consider using more efficient data structures like doubly linked
lists or other spatial indexing structures to speed up the clipping process.
5
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
3. Parallelization: Investigate parallel algorithms to speed up the clipping process, especially for
large polygons or complex clipping areas. Techniques like parallel processing or GPU
acceleration could be beneficial.