Filling a plane with triangles (triangulation)

I tried to create an image like the one below as a random background for a website, but after several tries, I couldn't find an algorithm that does the job.

enter image description here

What should the program do?

It should be able to fill the plane at random with triangles. These triangles need to be independent, so I just don't want to draw long lines on the canvas with the color that the triangles create.

The algorithms I have tried so far:

1.

  • Make random points
  • Make random connections below a certain length (this can snap to holes in the triangle mesh).
  • Try to figure out which connections form a triangle (I couldn't do it here)

2.

  • Start with one triangle
  • Create a new point near the existing junction and add a triangle there that does not cause intersections. This leads to problems when he left a small hole like in this picture:

    enter image description here

3.

  • Make random points
  • Make all possible connections (every point for every other)
  • Sort joints by length
  • For each junction starting with the shortest, if it does not intersect with any other drawn line. Otherwise, remove the connection.

This was my best approach, even if it took a long time to complete with just a few points. This is what the result looked like:

enter image description here

I didn't find a way to find out which joints form a triangle, and so I couldn't color them separately ...

So, I hope you know a way to create a beautiful canvas filled with a triangle like in the first picture and let me know ...

+3


source to share


1 answer


A good solution is to start at random points (with your preferred distribution) and apply the triangulation algorithm . Among them, Delaunay triangulation is a good candidate for its low computational complexity and code availability.



+2


source







All Articles