Triangulation
Ear clipping demo.
Made in 2025
Intro
One day while bored at school I drew a bunch of shapes and drew triangles between them. I was curious how I could do this programmatically. So, I learned how to use ear clipping how to triangulate.
Program
Simply click to add the points of the polygon. And, the program will automatically triangulate the polygon.

Implementation
The implementation is pretty simple. I used raylib since it was easy to use, and I wanted to get some c++ practice. All the points of the polygon are stored in a vector of vectors(std::vector<Vector2>). The first thing in ear-clipping is to make sure all the points are in counter-clockwise order. To do this, I calculated the center of the polygon and then sorted the points by their angle from the center. Then, I just iterated over the points and checked if the point was an ear. If it was, I removed it from the polygon and added it to the list of triangles. I repeated this process until there were no more points left in the polygon. In order to check if a point was an ear, I checked if the point was convex and if the triangle the point and it's neighbors formed intersected with other points.