Delaunay Triangulation stucked

I’ve been trying to port a delaunay triangulation algorithm to work with max.

The idea is to calculate a delaunay triangulation from a given list , representing x y point coordinates. [x y x y x y … ]. Actually i just need the values of the edges, i don’t even need to draw the result.

I’m currently using a .jar file from this processing library (http://www.leebyron.com/else/mesh/).
However, when i send the list, it gives me a null pointer exception, and i can’t figure out whats wrong… :S

myDelaunay gets declared twice, once at class-wide scope and then again in your list(float[][]) method. As far as Java is concerned, the more local declaration overrides the more general one, so the class level object is never being created, hence the exception.

Note that you’re doing a similar thing with the points array that you use both as a class variable and as a method argument.

There are a couple of other things. list(float[][]) won’t work for receiving lists from max. You’ll need to override list(float[]) or list(Atom[]) and then wrap things up into a 2D array yourself.

The designer of this library has made life more difficult than it should really be with the way the class is designed as well. There is no way of updating the points without creating a new instance of the object, which is pretty inefficient (at least the source comes with it, so it’s easy to address).

Primitive types in Java (float, double, int, char, short, long) don’t behave like normal object references that you can call methods on. To confuse matters there are a setting of corresponding classes – Float, Double, Integer, etc. (note the capital letters) that do expose methods. Under certain circumstances new(ish) versions of Java (>1.5?) are able to magically turn a primitive into an instance of its associated class, but I forget exactly what circumstances these are.

However, even then, I’m pretty sure that there isn’t an inside() method like you show here. I’m guessing that it means if the value of x appears in the set [w y z] in which case just do it long-hand: if(point[a]==point[i]||point[a]==point[j]||point[a]==point[k]).

Note that in your list(Atom[] args) method you are making the same mistake again by re-declaring N: if you write int N then that is declaring a new variable called N local to the method, which will hide the object variable N. You are also storing up a further NullPointerException by not allocating your array, and also not assigning your input to anything (rather you are assigning the values from your (unallocated) array to two new variables x and y.

It would be well worth your while to get hold of a decent Java reference to have to hand whilst you’re doing this, as it’ll go much quicker once you’re on top of how to properly declare and use variables.

Meanwhile, try this (untested, and assuming that all else is right with your code – I’m guessing the array length, could be wrong)

It makes sense, the long-hand way, i’v thought about it, just couldn’t get the correct syntax.
Also, the list function, i understand the issue with the N variable. With your example i’m just setting the variable N to the given list.

Regarding the decent Java reference you’r pretty right, it’s been a while since i learn code languages and from those time’s till now i’v been just patching :)

I’m now reading the c74 java-doc and when some specific doubts appear i just googled them, but you know, somewhere, someone on the internet is wrong :)

I’m very appreciated by your times and examples, this algorithm will take a part my Master thesis project, a toolkit for interactive data sonification. The triangulation will allow to draw the links in a physical model. Each link and mass will have their physical attributes according to the dynamics of the dataset under analysis, therefore, the user can play de data set. Of course i’ll reference you and the original source as well.