Write a program to clip a polygon using Sutherland Hodgeman algorithm.ipynb - Colab
Write a program to clip a polygon using Sutherland Hodgeman algorithm.ipynb - Colab
ipynb - Colab
def draw_polygon(polygon):
polygon.append(polygon[0])
xs, ys = zip(*polygon)
plt.plot(xs, ys)
# Example
polygon = [(10, 10), (100, 30), (90, 90), (20, 70)]
clip_edges = [[(20, 20), (80, 20)], [(80, 20), (80, 80)], [(80, 80), (20, 80)], [(20, 80), (20, 20)]]
plt.figure()
draw_polygon(polygon)
plt.title("Original Polygon")
plt.figure()
draw_polygon(clipped_polygon)
plt.title("Clipped Polygon")
plt.show()
https://colab.research.google.com/drive/1JZ4Fk7dl1IwnDqMqf2V_j2x9s8ly95vU#scrollTo=NwlVOhPlmILQ&printMode=true 1/2
11/5/24, 7:24 PM Write a program to clip a polygon using Sutherland Hodgeman algorithm.ipynb - Colab
https://colab.research.google.com/drive/1JZ4Fk7dl1IwnDqMqf2V_j2x9s8ly95vU#scrollTo=NwlVOhPlmILQ&printMode=true 2/2