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 › Quickhull3d sphere
Page Index Toggle Pages: 1
Quickhull3d sphere (Read 1172 times)
Quickhull3d sphere
Nov 28th, 2009, 12:47am
 
I have some code that generates the points of a sphere. I'm generating the points myself because I'll need to modulate them. But for now, it's just a regular sphere.
Once I generate the points, I use QuickHull3D to extract a hull, then get it's faces and draw them using TRIANGLES and QUADS. For some reason I don't understand some faces are missing from the sphere, about 4 or 5 faces on a 350 points sphere. I thought a convex hull (in 3d) would be a closed polyhedron, and so I was using this library as a shortcut (i.e. converting points to faces) to get a polyhedron, but maybe i'm wrong. Here's how I draw the faces (seems right to me):
Code:
QuickHull3D hull = new QuickHull3D(points);
Point3d[] vertices = hull.getVertices();
int[][] faces = hull.getFaces();

for (int i = 0; i < vertices.length; i++) {
 if (faces[i].length == 3) {
   applet.beginShape(PShape.TRIANGLES);
 } else if (faces[i].length == 4) {
   applet.beginShape(PShape.QUADS);
 } else {
   applet.stop(); // fatal error, never happens
 }
 for (int k = 0; k < faces[i].length; k++) {
   float x = (float) vertices[faces[i][k]].x * 200f;
   float y = (float) vertices[faces[i][k]].y * 200f;
   float z = (float) vertices[faces[i][k]].z * 200f;
   applet.vertex(x, y, z);
 }
 applet.endShape();
}


Just ignore the "applet." bits, I'm using eclipse.

I cannot post a screenshot because I'm too new here.

[edit: to get to the screenshot, click "WWW" down here and add "ext/out-0021.jpg" at the end of the url. sorry.]
Re: Quickhull3d sphere
Reply #1 - Nov 28th, 2009, 2:36am
 
Spotted the error:

Code:

for (int i = 0; i < vertices.length; i++) {

should be

Code:

for (int i = 0; i < faces.length; i++) {

I used code from the library's documentation which contains this error, I'll notify the author at once.
Page Index Toggle Pages: 1