简体   繁体   中英

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 multiple attempts I couldn't find an algorithm that gets the job done.

在此输入图像描述

What should the program do?

It should be able to fill a plane randomly with triangles. These triangles should all be independent, so I don't simply want to draw long lines on the canvas an color the triangles that are created.

Algorithms I've tried so far:

1.

  • Make random Points
  • Make random Connections with a length below a specific value (This could leed to holes in the triangle net)
  • Try to find out what connections make a triangle (I failed here)

2.

  • Start with a single triangle
  • Create a new Point close to an existing connection and add a triangle from there that doesn't cause any intersections. This lead to problems whenever it left a little hole like in this picture:

    在此输入图像描述

3.

  • Make random points
  • Make all possible connections (every point to every other)
  • Sort the connections by length
  • For every connection starting with the shortest draw if it isn't intersecting with any other drawn line. Otherwise delete the connection.

This was actually my best attemt even if it took the program far to long to get it done with only a few points. This is how the result looked:

在此输入图像描述

I didn't find a way to find out what connections make a triangle and therefor I couldn't color them indipendently...

So hopefully you know a way to create a nice triangle-filled canvas like in the first picture and let me know...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM