Igeo delaunay2D

Keeping up looking to the Igeo library for processing, I found the delaunay2D class and had a go at it. Below is an example that creates some random points and invokes the delaunay2D class in iGeo to solve a delaunay triangulation in 2d.

It’s a very basic example, more to follow. . .

enjoy!

import processing.opengl.*;
import igeo.*;

void setup() {
size( 1200, 800, IG.GL );
frameRate(0.5);// the redrawing process is slow so we see every new triangulation
//IG.top();// Maximises the top vieport
strokeWeight(0.1);
}

double z = 0.0;
int ptNo = 20; // Specifies the number of random points used for the triagulation

void draw()

{

IVec2[] myVectors = new IVec2[ptNo];

z = z + 20.0;//creates a different triangulation every 20 units along the z axis

for (int i=0; i<ptNo; i++)

{
myVectors[i] = new IVec2(random(0, 1000), random(0, 1000));
}

IDelaunay2D myDelaunay = new IDelaunay2D();

IVec2[][] myTriangles = myDelaunay.getTriangles(myVectors);

for (int i = 0; i<myTriangles.length; i++)
{
IVec[] ver = new IVec[3];
for (int j = 0; j<3; j++)
{

ver[j] = myTriangles[i][j].to3d(z);
new IPoint(ver[j]).clr(((255/20)*i), 0, (255/20)*(20-i)) ;
}
//new ISurface(ver).clr(255, 0, 0);// uncomment to construct 3 point surfaces
new ICurve(ver).clr(int(random(255)));
}
}

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales License.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: