Assignment 1 of the course ED5310 at IIT Madras
Aim : This assignment is on the implementation of the triangulation algorithm (preferably
This is a modular implementation of polygon triangulation consisting of three parts.
This piece of code generates the polygon dataset. For a given n number of vertices, We randomly choose angles from
Using the function polygon_generator(n)
we can create a polygon (Convex or Non-Convex) of n vertices. The Ooutput of the said function is a list of n vertices in counter-clock wise order as required by the later modules. One can also visualise the same in the same code using matplotlib based polygon viewer.
Ear clipping algorithm can be referred from the book "COMPUTATIONAL GEOMETRY IN C - JOSEPH O'ROURKE" or from here
This code consists of the implementation of the ear clipping algorithm as per the book. It's runtime is Polygon
class which is defined by an ordered set of vertices in counter-clock-wise manner.
The function triangulate()
can triangulate any given polygon which is an instance of the Polygon
class. Similarly, to visualise triangulation, one can make use of the function triangulate_and_plot()
. Here is an example plot produced.
This code contains the CGAL impementation of triangulation using the Constrained_triangulation_2
class from the CGAL
library. We compare the runtimes of both the implementations for polygons of sizes 4 to 200. Plot is attached below.