I already have the theory behind the algorithm but since I have no formal education I am having trouble translating it into code. More information about the theory is below. Any help is appreciated.
make_shape
You are given x vertices and their coordinates relative to a corner (let it be relative to the bottom left corner for simplicity's sake) as an argument to a function.
using vertices_t = std::vector< std::pair< double,
double > >;
make_shape( vertices_t const & vertices );
// doesnt need to be a vector of a pair of doubles.
// use anything else, like a valarray of ints if you so choose
In return, you are to construct a an object who describes the shape in triangles (primitives)
using triangles_t = std::vector< std::tuple< std::size_t,
std::size_t,
std::size_t > >;
triangles_t make_shape( vertices_t vertices );
// once again, it does not need to be a vector of a 3 tuple of size_t
The theory: any shape can be composed of triangles. The number of triangles required is equal to the number of vertices minus two.
auto && triangles = vertices.size( ) - 2;
The algorithm is simple: you take a vertex and two adjacent vertices and connect them. Then, alternatingly increment the vertices and store the last incremented vertex as your three next vertices. This will result in a series of triangles that composes any shape. The issue arises with concave shapes, where picking the vertex matters.
The following are some images of how the algorithm looks in action
