-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTriangulation.cpp
More file actions
51 lines (39 loc) · 2.63 KB
/
Triangulation.cpp
File metadata and controls
51 lines (39 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "triangulate.h"
void main(int argc, char **argv)
{
// Small test application demonstrating the usage of the triangulate class.
// Create a contour by pushing them onto an stl vector.
Vector2dVector a;
a.push_back(Vector2d(0, 6));
a.push_back(Vector2d(0, 0));
a.push_back(Vector2d(3, 0));
a.push_back(Vector2d(4, 1));
a.push_back(Vector2d(6, 1));
a.push_back(Vector2d(8, 0));
a.push_back(Vector2d(12, 0));
a.push_back(Vector2d(13, 2));
a.push_back(Vector2d(8, 2));
a.push_back(Vector2d(8, 4));
a.push_back(Vector2d(11, 4));
a.push_back(Vector2d(11, 6));
a.push_back(Vector2d(6, 6));
a.push_back(Vector2d(4, 3));
a.push_back(Vector2d(2, 6));
// allocate an STL vector to hold the answer.
Vector2dVector result;
// Invoke the triangulator to triangulate this polygon.
Triangulate::Process(a, result);
// print out the results.
int tcount = result.size() / 3;
for (int i = 0; i<tcount; i++)
{
const Vector2d &p1 = result[i * 3 + 0];
const Vector2d &p2 = result[i * 3 + 1];
const Vector2d &p3 = result[i * 3 + 2];
printf("Triangle %d => (%0.0f,%0.0f) (%0.0f,%0.0f) (%0.0f,%0.0f)\n", i + 1, p1.GetX(), p1.GetY(), p2.GetX(), p2.GetY(), p3.GetX(), p3.GetY());
}
}