Hey, I drew many small cylinders. First, I used a array to store all data, e.g. {x1,y1,z1,x2,y2,z2,x3,y3,z3}.
I wrote a function that can draw a cylinder according to two inputted points (x1,y1,z1) and (x2,y2,z2), or (x2,y2,z2) and (x3,y3,z3). Here is the function.
public static void drawCylinder(GL2 gl2, double x1, double y1, double z1, double x2, double y2, double z2, double radius) {
double dx = x2 - x1;
double dy = y2 - y1;
double dz = z2 - z1;
double distance = Math.sqrt(dx*dx + dy*dy + dz*dz);
double px = x1;
double py = y1;
double pz = z1;
double bx = px;
double by = py;
double bz = distance + pz;
double sx = bx - x1;
double sy = by - y1;
double sz = bz - z1;
double fx = sy * dz - dy * sz;
double fy = sz * dx - sx * dz;
double fz = sx * dy - dx * sy;
double ax = x2 - bx;
double ay = y2 - by;
double az = z2 - bz;
double length = Math.sqrt(ax * ax + ay * ay + az * az);
float angle = (float)(Math.acos((distance*distance*2 - length*length)/(2*distance*distance))*180.0f / Math.PI);
GLUT glut = new GLUT();
gl2.glPushMatrix();
gl2.glTranslated(x1, y1, z1);
gl2.glRotated(angle, fx, fy, fz);
glut.glutSolidCylinder(radius, distance, 32, 32);
gl2.glPopMatrix();
}
There are many small gaps like this:
. How can I fill these gaps?