I imagine most people are using this to make a 3D mesh, not just trying to plot the result, and as such it would be nice to know which points in the input array make up each triangle. For example, if I know the input points are (0, 2) (.4, 0) (-.4, 0) (0, -2), I can run the algorithm and get two triangles. Suppose it tells me that the triangles are
(.4, 0) (-.4, 0) (0, -2) and (0, 2) (.4, 0) (-.4, 0). That's enough to draw lines, but if my goal is to tell OpenGL or something how to triangulate my points with an indexed VBO, I's like the answer in this form: 2,3,4 and 1,2,3. This allows me to reference the original vertex arrays if I want by iterating over the indices and doing vert[2], vert[3], vert[4].
I've tried doing pointer subtraction between the vertices array (both the original and the one owned by the Delauney class) and I'm getting out of bounds numbers:
for (const auto& tri : triangles) {
int index = tri.a - triangulation.getVertices();
// or
int index = std::distance(triangulation.getVertices(), tri.a);
}
I get negative numbers and things that indicate that the pointer doesn't point into that vector. If I'm not mistaken, I have to do a linear search through all of the input vertices for each point in the triangle and do floating point comparison to figure out the index. A linear search through each of the 4 points isn't a big deal, but O(N^2) isn't cool if I have a million. Am I missing something?
Thanks for writing this library, it does most of the heavy lifting for what I need.
I imagine most people are using this to make a 3D mesh, not just trying to plot the result, and as such it would be nice to know which points in the input array make up each triangle. For example, if I know the input points are (0, 2) (.4, 0) (-.4, 0) (0, -2), I can run the algorithm and get two triangles. Suppose it tells me that the triangles are
(.4, 0) (-.4, 0) (0, -2) and (0, 2) (.4, 0) (-.4, 0). That's enough to draw lines, but if my goal is to tell OpenGL or something how to triangulate my points with an indexed VBO, I's like the answer in this form: 2,3,4 and 1,2,3. This allows me to reference the original vertex arrays if I want by iterating over the indices and doing vert[2], vert[3], vert[4].
I've tried doing pointer subtraction between the vertices array (both the original and the one owned by the Delauney class) and I'm getting out of bounds numbers:
for (const auto& tri : triangles) {
int index = tri.a - triangulation.getVertices();
// or
int index = std::distance(triangulation.getVertices(), tri.a);
}
I get negative numbers and things that indicate that the pointer doesn't point into that vector. If I'm not mistaken, I have to do a linear search through all of the input vertices for each point in the triangle and do floating point comparison to figure out the index. A linear search through each of the 4 points isn't a big deal, but O(N^2) isn't cool if I have a million. Am I missing something?
Thanks for writing this library, it does most of the heavy lifting for what I need.