question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DelaunayTriangulator is occasionally incorrect (6-point example)

See original GitHub issue

Issue details

I am attempting to use the DelaunayTriangulator to calculate adjacency information in a voronoi diagram. Unfortunately, it appears that the triangulator occasionally triangulates quads in the wrong direction. Here’s a picture of one of the failing cases I’m encountering:

delaunay_fail

The background is the rasterized voronoi of the points, to emphasize the problem. The quad made up of points (0, 3, 1, 2) should be triangulated into (0, 3, 1) and (1, 2, 0), but instead it gets cut in the other direction. Adding another point somewhere else in the diagram (even far away) can sometimes flip this particular quad to be correct.

Reproduction steps/code

This test case reproduces the issue exactly as shown in the picture.

import com.badlogic.gdx.math.DelaunayTriangulator;
import com.badlogic.gdx.utils.ShortArray;

public class DelaunayTest {

	public static void main(String[] args) {
		float[] points = new float[12];
		points[0] = (float) 2000.7620849609375;
		points[1] = (float) 3044.865234375;
		points[2] = (float) 3121.152099609375;
		points[3] = (float) 2331.909912109375;
		points[4] = (float) 1909.64794921875;
		points[5] = (float) 1924.1240234375;
		points[6] = (float) 3096.233642578125;
		points[7] = (float) 2911.776611328125;
		points[8] = (float) 776.0308227539062;
		points[9] = (float) 658.64501953125;
		points[10] = (float) 3619.53564453125;
		points[11] = (float) 163.5050811767578;

		DelaunayTriangulator delaunay = new DelaunayTriangulator();
		ShortArray trigs = delaunay.computeTriangles(points, false);

		for (int c = 0, n = trigs.size; c < n; c += 3) {
			System.out.format("(%d, %d, %d)\n", trigs.get(c), trigs.get(c+1), trigs.get(c+2));
		}

		// Prints out:
		// (4, 2, 5)
		// (2, 3, 1) // wrong!
		// (2, 4, 0)
		// (3, 5, 1)
		// (2, 0, 3) // wrong!
		// (5, 2, 1)
	}

}

Version of LibGDX and/or relevant dependencies

master (as of 12/15/2016, commit 52bbab3)

Please select the affected platforms

  • Android
  • iOS (robovm)
  • iOS (MOE)
  • HTML/GWT
  • Windows
  • Linux
  • MacOS I’ve only tested on Windows 7, but the problem seems algorithmic.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tommyettingercommented, Sep 9, 2020

So we contributors have been going through issues recently and closing any that no longer represent legitimate bugs. This is not one of those cases. The example code provided by @SpexGuy was very helpful in confirming the bug, but actually solving it was a can of worms, and I’m not certain I’ve got a fix for all buggy situations… But it’s something. What I found was that the point sorting code was sometimes not producing a correct ascending-x order, and while I’m not totally sure why this happens, an extra check is all that’s needed to make sure that the sort is correct. Once the sort is correct, the triangles match the diagram given in the first post. This is a two-line fix, and as long as there isn’t some extra unknown bug, it should be enough. I’ll PR the change in a few minutes.

0reactions
MrStahlfelgecommented, Sep 11, 2020

Fix is merged.

Read more comments on GitHub >

github_iconTop Results From Across the Web

delaunay triangulations in the plane
Figure 6 shows an example of the Delaunay triangulation of a set of points in the plane. Delaunay triangulation is unique when S...
Read more >
Delaunay triangulation - Wikipedia
In mathematics and computational geometry, a Delaunay triangulation for a given set P of discrete points in a general position is a triangulation...
Read more >
Delaunay Triangulation - UCSB Computer Science
A priori, the existence such a triangulation seems too good to be true: every point set be triangulated so that each of its...
Read more >
Blocking Delaunay triangulations - ScienceDirect.com
Considering the properties of the Delaunay triangulation, we propose the following two simple operations to block Delaunay edges. Blocking a single edge is...
Read more >
Delaunay Triangulations
Determine a triangulation of A in R2, then raise points to desired ... angle is reduced to the problem of finding a Delaunay...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found