Delaunay triangulator class in C++
Delaunay triangulation is a fundamental algorithm which has a vast range of applications, both in game development and in other research areas, such as AI and graph theory.
Many libraries include this algorithm among their functions , but they require adding many include files or link to big dll libraries just for getting the functions needed to run the algorithm. In many cases this is not a viable option.
This Delaunay triangulation class is contained in a single include file and it triangulates a set of unordered points in 2D space in the fastest way possible. In addition, the adjacency of each triangle is computed and redundant vertices are discarded.The algorithm used is the flip algorithm in a divide and conquer fashion.
What our users say:
"Great code that works as expected. It quickly triangulates 500+ points, removing duplicates and retaining original point indicies. Easier to use than Triangle in a c++ app and is a low-cost alternative for a commercial application." - Jason Dunn
An example of usage is shown below:
// first , define some random points in 2d space double Px,Py; int N=10; for ( int i=0; i
SelectObject(&penBlue); // and a solid red brush CBrush brushRed(RGB(155, 155, 155)); CBrush* pOldBrush = pDC->SelectObject(&brushRed); // Find the midpoints of the top, right, left, and bottom // of the client area. They will be the vertices of our polygon. pts.x = (int)VertexPtr[ p1 ].x; pts.y = (int)VertexPtr[ p1 ].y; pts.x = (int)VertexPtr[ p2 ].x; pts.y = (int)VertexPtr[ p2 ].y; pts.x = (int)VertexPtr[ p3 ].x; pts.y = (int)VertexPtr[ p3 ].y; // Calling Polygon() on that array will draw three lines // between the points, as well as an additional line to // close the shape--from the last point to the first point // we specified. pDC->Polygon(pts, 3); // Put back the old objects. pDC->SelectObject(pOldPen); pDC->SelectObject(pOldBrush); } for ( i=0; i
// if you want to draw the adjacent triangle just use these lines of code
j=0; // we want adjacent traingles to triangle number 0 int p12; p12=TrianglePtr[ j ].t1; if ( p12!=-1) DrawPoly( pDC , p12 ,col2 ); p12=TrianglePtr[ j ].t2; if ( p12!=-1) DrawPoly( pDC , p12 ,col1 ); p12=TrianglePtr[ j ].t3; if ( p12!=-1) DrawPoly( pDC , p12 ,col3 );