-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelaunay_triangulation.hpp
More file actions
30 lines (21 loc) · 990 Bytes
/
delaunay_triangulation.hpp
File metadata and controls
30 lines (21 loc) · 990 Bytes
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
#include <vector>
#include <array>
#include <glm/glm.hpp>
struct TriangleAdj {
std::array<int, 3> vertices;
std::array<int, 3> adjacencies;
TriangleAdj() : vertices{0, 0, 0}, adjacencies{-1, -1, -1} {}
};
struct DelaunayResult {
std::vector<glm::vec2> points;
std::vector<TriangleAdj> triangles;
};
bool point_within_triangle(const glm::vec2 &p, const glm::vec2 &a, const glm::vec2 &b, const glm::vec2 &c);
std::pair<float, glm::vec2> normalize_points(std::vector<glm::vec2> &points);
// using binning
void sort_points_by_spatial_proximity(std::vector<glm::vec2> &points);
// find which triangle contains a point
int find_containing_triangle(const glm::vec2 &p, int start_idx, const std::vector<glm::vec2> &points,
const std::vector<TriangleAdj> &triangles);
bool in_circumcircle(const glm::vec2 &p, const glm::vec2 &v1, const glm::vec2 &v2, const glm::vec2 &v3);
DelaunayResult delaunay_triangulate(std::vector<glm::vec2> points);