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.]