Strange Mesh library Voronoi issue
in
Contributed Library Questions
•
2 years ago
Hi all,
I'm trying to combine Geomerative with
Lee Byron's Mesh library to create Voronoi and Delaunay meshes with the points from a Geomerative object. The issue I'm having is that the Voronoi class refuses to work with the points coming out of Geomerative. The Delaunay works, and the Voronoi works if I use random numbers instead, but using the points from Geomerative it throws an Array Index Out of Bounds: 0 error. Any suggestions? Here's some code:
- import megamu.mesh.*;
- import geomerative.*;
- RFont f;
- RShape grp;
- RPoint[] coords;
- float[][] points;
- Delaunay d;
- Voronoi v;
- void setup() {
- size(500, 500);
- smooth();
- background(255);
- RG.init(this); //start geomerative
- //convert text to points
- grp = RG.getText("Kyle", "GenBasB.ttf", 150, CENTER);
- RG.setPolygonizer(RG.ADAPTATIVE);
- coords= grp.getPoints();
- //convert from RPoint[] to float[][]
- float[][] points=new float[coords.length][2];
- for(int i=0; i<points.length; i++) {
- //voronoi works with random numbers only; delaunay works with both???
- points[i][0]=coords[i].x;
- points[i][1]=coords[i].y;
- //println(points[i][0]);
- //points[i][0]=random(-width/2, width/2); //random numbers work!!
- //points[i][1]= random(-height/2, height/2);
- }
- d= new Delaunay(points);
- v= new Voronoi(points); //error on this line: Array Index Out of Bounds Exception: 0
- }
- void draw() {
- background(255);
- noFill();
- translate(width/2, height/2);
- stroke(255, 0, 0, 100);
- //draw the voronoi
- float[][] myEdges = v.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 );
- }
- stroke(0, 0, 255, 100);
- //draw the delaunay
- float[][] myEdges2 = d.getEdges();
- for(int i=0; i<myEdges2.length; i++)
- {
- float startX = myEdges2[i][0];
- float startY = myEdges2[i][1];
- float endX = myEdges2[i][2];
- float endY = myEdges2[i][3];
- line( startX, startY, endX, endY );
- }
- }
Cheers!
1