-1

im using the Mesh library in processing to create a grid of triangles based on an array of points. my problem is that this library can only return an array of lines that make up the triangles and not the triangles themselfs. does anyone know how to get all the the triangles?

the library is here: http://leebyron.com/mesh/

and here's a picture for refrence

yoav sarfaty
  • 43
  • 1
  • 1
  • 8
  • Have you tried googling "convert set of lines to triangles" to find algorithms that might help you? What happened when you tried them? – Kevin Workman Aug 11 '17 at 16:32
  • I can't find anything that will not take forever... – yoav sarfaty Aug 11 '17 at 17:14
  • I would like a different library perhaps – yoav sarfaty Aug 11 '17 at 17:14
  • Questions asking us to recommend a library are off-topic for Stack Overflow. I'd recommend comparing the amount of time it will take to try something against the amount of time you'll spend waiting for an answer. It's hard to answer general "how do I do this" type questions. You'll have much better luck if you try something and post a specific "I tried X, expected Y, but got Z instead" type question. So I recommend that you try something and post a more specific question, which will make it more likely that you get an answer. – Kevin Workman Aug 11 '17 at 17:16

1 Answers1

0

Good question. On first, solution is to take library that can give you result in wanted format. You need Delaunay triangulation not Delaunay diagram, what this library provides.

It is possible to obtain triangles from result library provide quite simple. If inner diagram point has n edges (getLinked() method), than it is part of n triangles. Other edges of triangles are calcualted by sorting edges by angle. If point is outer (on convex hull) than angle between one pair of edges is larger than 180deg and on that pair triangle doesn't exist.

Algorithm is like:

for each point p1:
  neighbours = delaunay.getLinked(p1)
  sort neighbours by angle to point p1
  for i=0 to size(neighbours)
    p2 = neighbours[i]
    p3 = neighbours[(i+1) % size(neighbours)]
    if (angle(p3, p1) - angle(p2, p1)) % 360deg > 180deg:
      continue  # Outer triangle
    if p2 > p1 and p3 > p1:
      continue  # Already processed
    print result triangle (p1, p2, p3)

Check (p2, p3 > p1) is to remove identical triangles, since each triangle is produced three times.

Roman Pokrovskij
  • 9,449
  • 21
  • 87
  • 142
Ante
  • 5,350
  • 6
  • 23
  • 46