We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Lee Byron Mesh library
Page Index Toggle Pages: 1
Lee Byron Mesh library (Read 1640 times)
Lee Byron Mesh library
Sep 21st, 2009, 4:20pm
 
I am just playing around with the Mesh Library by Lee Byron and try to get the example to work. http://leebyron.com/else/mesh/

The first example he provides works fine
Code:
 
import megamu.mesh.*;
float[][] points = new float[5][2];

Delaunay myDelaunay ;
void setup(){

 size(600,600);
 background(255);
points[0][0] = 120; // first point, x
points[0][1] = 230; // first point, y
points[1][0] = 150; // second point, x
points[1][1] = 105; // second point, y
points[2][0] = 320; // third point, x
points[2][1] = 113; // third point, y
points[3][0] = 220; //
points[3][1] = 413; //
points[4][0] = 160; //
points[4][1] = 253; //


myDelaunay = new Delaunay( points );
}

void draw(){
 background(255);
 stroke(9);

   float[][] myEdges = myDelaunay.getEdges();

 for(int i=0; i<myEdges.length; i++)
 {
   float startX = myEdges[i][0];
   float startY = myEdges[i][1];
   float endX = myEdges[i][2];
   float endY = myEdges[i][3];
   line( startX, startY, endX, endY );
 }

}



but using the getLinks() example i get an indexOutofBounds

any ideas why ?

Code:
 
import megamu.mesh.*;
float[][] points = new float[5][2];

Delaunay myDelaunay ;
void setup(){

 size(600,600);
 background(255);
points[0][0] = 120; // first point, x
points[0][1] = 230; // first point, y
points[1][0] = 150; // second point, x
points[1][1] = 105; // second point, y
points[2][0] = 320; // third point, x
points[2][1] = 113; // third point, y
points[3][0] = 220; //
points[3][1] = 413; //
points[4][0] = 160; //
points[4][1] = 253; //


myDelaunay = new Delaunay( points );
}

void draw(){
 background(255);
 stroke(9);

int[][] myLinks = myDelaunay.getLinks();

for(int i=0; i<myLinks.length; i++)
{
int startIndex = myLinks[i][0];
int endIndex = myLinks[i][1];

float startX = points[startIndex][0];
float startY = points[startIndex][1];
float endX = points[endIndex][2];
float endY = points[endIndex][3];
line( startX, startY, endX, endY );
}

}
Re: Lee Byron Mesh library
Reply #1 - Sep 22nd, 2009, 4:55am
 
When you have an exception, it is nice to mark which line makes the exception, it is easier to track the cause.
Anyway, I can guess where it is:
float endX = points[endIndex][2];
float endY = points[endIndex][3];

You access points which is [5][2], not [5][4].
Re: Lee Byron Mesh library
Reply #2 - Sep 22nd, 2009, 10:36am
 
sorry, for not highlighting. you are right,      
float endX = points[endIndex][2]; was the problem

i didnt write that code, it was on the examples page, but i didnt understand what you meant by
Quote:
You access points which is [5][2], not [5][4].
Re: Lee Byron Mesh library
Reply #3 - Sep 22nd, 2009, 12:00pm
 
I guess you have an ArrayIndexOutOfBounds error instead.
The name tries to be explicit: you access an array with an index out of the bounds you defined for it. The bounds are [5][2] in the points definition. You try to access the index 2 on the second dimension, but it is limited to the range 0 .. 1

I guess the correct code is:
Code:
float endX = points[endIndex][0];
float endY = points[endIndex][1];
instead.
Re: Lee Byron Mesh library
Reply #4 - Sep 22nd, 2009, 1:07pm
 
Yep, you are right again. thx!
Page Index Toggle Pages: 1