# How to generate tiled delaunay triangulation mesh (delaunay triangulation within a rectangle with triangles connecting opposing edges)?

I have a nice triangulation of a square mesh. The way I do this currently is

1. generate square mesh (two triangles), from (0.,0.) to (1.,1.) (axis-aligned and normalized for simplicity)
2. add point somewhere within square (poisson disk sampling)
3. detect which triangle point falls within
4. subdivide into 3 triangles
5. iterate over all tris, perform "delaunay flips" where necessary
6. GOTO 2

This works great (a bit simplified, as there's also edge-case detection code to account for colinear points, fp precision errors, etc...).

Anyways, what I want to do now is have the edges of this square "wrap".

EDIT: Upon request, here are some illustrations to help convey my problem:

So, we have an initial set of pts:

A normal delaunay triangulation would generate something like this:

What I want is a tessalated delaunay triangulation. That is, what edges would have to exist to allow this to be infinitely tile-able:

An example set of edges might be like this:

Now, imagine if you left those connections, but didn't tile them. I've drawn just the "wrapping" connections for the red dot and the purple dot in green, assuming there is only one instance of each dot in view (centered around the initially displayed set of dots):

Already, it's a topological mess. But in theory, I'd expect it would work, assuming I stick to some implementation constraints.

So, the plan would be to create a mesh containing all these pts and their respective connections. I would have some offset, and move the points in the vertex shader as a modulus of that offset. That way, every point will exist as "the closest instance of that point in the infinitely tiling plane" to the offset (for example, the camera). Since all the connections are in place, I wouldn't have to mess with them, and would get infinitely-scrolling (repeating) "terrain". All the topologically-messy-wrapping connections would be "backfacing" triangles, and would be culled... right?

Edit: Ok no they would not necessarily be backfacing... shoot. (if the wrap of the triangle was both vertically and horizontally wrapped, it would be back to frontfacing. My best guess at a solution is to, in the vert shader, artificially lower all the pts "close" to being wrapped, so any wonky giant tri's show up way below any legitimate tris. #hack.

Ok. off to try this. Will report back with any updates...

• Ok wait. Actually, in typing this up, I may have come up with a solution. Going to give it a try and see how it goes, but figured I'd make the post anyways so I can leave my answer for anyone in the future. Hopefully be back soon! (If anyone still has a good answer, input is still appreciated!) Commented Feb 13, 2016 at 20:56
• Attach an image of what you want to achieve. Without that the question is rather unclear. Commented Feb 14, 2016 at 5:21