draw bottom half sphere 3d

I'1000 trying to create the centre half of a sphere. Basically to create a sphere, stack numbers and piece numbers are given, and at that place are ii variables phi (for slices) and theta (for stacks) responsible for how much to progress. And the procedure is divided into creating bottom cap, body, and top cap (every bit seen below). To achieve heart half (theta of middle 50% as beneath), nosotros need to omit the caps, and somehow alter the body. I was playing around with stack numbers (one/4*stackNumbers to 3/four*stackNumbers) merely didn't requite the result I wanted.

How should I modify the sphere generation to attain the heart half ( pi/4 <theta <pi*iii/4 )? My overall trouble is how can I split the sphere into iii different parts upper 25%, heart l%, and bottom 25%? (25% in terms of angle, i.due east. theta)

Here is the popular code for generating a sphere programmatically:

enter image description here

          private void generateSphere(int stackNumber, int sliceNumber, boolean facingOut) {     int capVertexNumber = 3 * sliceNumber;     int bodyVertexNumber = 4 * sliceNumber * (stackNumber - 2);     int vertexNumber = (2 * capVertexNumber) + bodyVertexNumber;     int triangleNumber = (ii * capVertexNumber) + (six * sliceNumber * (stackNumber - ii));      vertices = new float[iii * vertexNumber];     normals = new float[3 * vertexNumber];     texCoords = new float[2 * vertexNumber];     indices = new char[triangleNumber];      // bottom cap     // createCap(stackNumber, sliceNumber, false, facingOut);      // body     createBody(stackNumber, sliceNumber, facingOut);      // height cap     createCap(stackNumber, sliceNumber, true, facingOut); }  individual void createCap(int stackNumber, int sliceNumber, boolean elevation, boolean facingOut) {      float stackPercentage0;     float stackPercentage1;      if (!top) {         stackPercentage0 = ((float) (stackNumber - ane) / stackNumber);         stackPercentage1 = 1.0f;      } else {         stackPercentage0 = (1.0f / stackNumber);         stackPercentage1 = 0.0f;     }      bladder t0 = stackPercentage0;     float t1 = stackPercentage1;     double theta0 = stackPercentage0 * Math.PI;     double theta1 = stackPercentage1 * Math.PI;     double cosTheta0 = Math.cos(theta0);     double sinTheta0 = Math.sin(theta0);     double cosTheta1 = Math.cos(theta1);     double sinTheta1 = Math.sin(theta1);      for (int slice = 0; piece < sliceNumber; slice++) {         bladder slicePercentage0 = ((float) (slice) / sliceNumber);         float slicePercentage1 = ((float) (slice + 1) / sliceNumber);         double phi0 = slicePercentage0 * 2.0 * Math.PI;         double phi1 = slicePercentage1 * two.0 * Math.PI;         float s0, s1;         if (facingOut) {             s0 = one - slicePercentage0;             s1 = 1 - slicePercentage1;         } else {             s0 = slicePercentage0;             s1 = slicePercentage1;         }         bladder s2 = (s0 + s1) / 2.0f;         double cosPhi0 = Math.cos(phi0);         double sinPhi0 = Math.sin(phi0);         double cosPhi1 = Math.cos(phi1);         double sinPhi1 = Math.sin(phi1);          float x0 = (bladder) (sinTheta0 * cosPhi0);         bladder y0 = (float) cosTheta0;         float z0 = (float) (sinTheta0 * sinPhi0);          float x1 = (float) (sinTheta0 * cosPhi1);         float y1 = (bladder) cosTheta0;         float z1 = (float) (sinTheta0 * sinPhi1);          float x2 = (bladder) (sinTheta1 * cosPhi0);         float y2 = (float) cosTheta1;         float z2 = (float) (sinTheta1 * sinPhi0);          vertices[vertexCount + 0] = x0;         vertices[vertexCount + 1] = y0;         vertices[vertexCount + ii] = z0;          vertices[vertexCount + iii] = x1;         vertices[vertexCount + 4] = y1;         vertices[vertexCount + 5] = z1;          vertices[vertexCount + 6] = x2;         vertices[vertexCount + 7] = y2;         vertices[vertexCount + 8] = z2;          if (facingOut) {             normals[vertexCount + 0] = x0;             normals[vertexCount + 1] = y0;             normals[vertexCount + 2] = z0;              normals[vertexCount + 3] = x1;             normals[vertexCount + 4] = y1;             normals[vertexCount + 5] = z1;              normals[vertexCount + half dozen] = x2;             normals[vertexCount + seven] = y2;             normals[vertexCount + 8] = z2;         } else {             normals[vertexCount + 0] = -x0;             normals[vertexCount + 1] = -y0;             normals[vertexCount + two] = -z0;              normals[vertexCount + 3] = -x1;             normals[vertexCount + iv] = -y1;             normals[vertexCount + 5] = -z1;              normals[vertexCount + half dozen] = -x2;             normals[vertexCount + seven] = -y2;             normals[vertexCount + 8] = -z2;         }          texCoords[texCoordCount + 0] = s0;         texCoords[texCoordCount + 1] = t0;         texCoords[texCoordCount + two] = s1;         texCoords[texCoordCount + 3] = t0;         texCoords[texCoordCount + 4] = s2;         texCoords[texCoordCount + 5] = t1;          if ((facingOut && superlative) || (!facingOut && !top)) {             indices[indexCount + 0] = (char) (triangleCount + 1);             indices[indexCount + ane] = (char) (triangleCount + 0);             indices[indexCount + 2] = (char) (triangleCount + 2);         } else {             indices[indexCount + 0] = (char) (triangleCount + 0);             indices[indexCount + 1] = (char) (triangleCount + i);             indices[indexCount + 2] = (char) (triangleCount + 2);         }          vertexCount += 9;         texCoordCount += 6;         indexCount += 3;         triangleCount += three;     }  }  private void createBody(int stackNumber, int sliceNumber, boolean facingOut) {     for (int stack = 1; stack < stackNumber - ane; stack++) {         bladder stackPercentage0 = ((float) (stack) / stackNumber);         float stackPercentage1 = ((bladder) (stack + 1) / stackNumber);          bladder t0 = stackPercentage0;         float t1 = stackPercentage1;          double theta0 = stackPercentage0 * Math.PI;         double theta1 = stackPercentage1 * Math.PI;         double cosTheta0 = Math.cos(theta0);         double sinTheta0 = Math.sin(theta0);         double cosTheta1 = Math.cos(theta1);         double sinTheta1 = Math.sin(theta1);          for (int slice = 0; piece < sliceNumber; slice++) {             float slicePercentage0 = ((float) (slice) / sliceNumber);             float slicePercentage1 = ((float) (piece + 1) / sliceNumber);             double phi0 = slicePercentage0 * ii.0 * Math.PI;             double phi1 = slicePercentage1 * two.0 * Math.PI;             float s0, s1;             if (facingOut) {                 s0 = i.0f - slicePercentage0;                 s1 = 1.0f - slicePercentage1;             } else {                 s0 = slicePercentage0;                 s1 = slicePercentage1;             }             double cosPhi0 = Math.cos(phi0);             double sinPhi0 = Math.sin(phi0);             double cosPhi1 = Math.cos(phi1);             double sinPhi1 = Math.sin(phi1);              bladder x0 = (float) (sinTheta0 * cosPhi0);             float y0 = (float) cosTheta0;             float z0 = (float) (sinTheta0 * sinPhi0);              float x1 = (bladder) (sinTheta0 * cosPhi1);             float y1 = (float) cosTheta0;             float z1 = (bladder) (sinTheta0 * sinPhi1);              float x2 = (float) (sinTheta1 * cosPhi0);             float y2 = (float) cosTheta1;             float z2 = (float) (sinTheta1 * sinPhi0);              float x3 = (float) (sinTheta1 * cosPhi1);             float y3 = (float) cosTheta1;             bladder z3 = (float) (sinTheta1 * sinPhi1);              vertices[vertexCount + 0] = x0;             vertices[vertexCount + one] = y0;             vertices[vertexCount + two] = z0;              vertices[vertexCount + 3] = x1;             vertices[vertexCount + four] = y1;             vertices[vertexCount + 5] = z1;              vertices[vertexCount + vi] = x2;             vertices[vertexCount + 7] = y2;             vertices[vertexCount + 8] = z2;              vertices[vertexCount + 9] = x3;             vertices[vertexCount + 10] = y3;             vertices[vertexCount + 11] = z3;              if (facingOut) {                 normals[vertexCount + 0] = x0;                 normals[vertexCount + 1] = y0;                 normals[vertexCount + ii] = z0;                  normals[vertexCount + iii] = x1;                 normals[vertexCount + 4] = y1;                 normals[vertexCount + 5] = z1;                  normals[vertexCount + six] = x2;                 normals[vertexCount + 7] = y2;                 normals[vertexCount + 8] = z2;                  normals[vertexCount + nine] = x3;                 normals[vertexCount + 10] = y3;                 normals[vertexCount + xi] = z3;             } else {                 normals[vertexCount + 0] = -x0;                 normals[vertexCount + 1] = -y0;                 normals[vertexCount + ii] = -z0;                  normals[vertexCount + 3] = -x1;                 normals[vertexCount + 4] = -y1;                 normals[vertexCount + five] = -z1;                  normals[vertexCount + half dozen] = -x2;                 normals[vertexCount + 7] = -y2;                 normals[vertexCount + 8] = -z2;                  normals[vertexCount + 9] = -x3;                 normals[vertexCount + x] = -y3;                 normals[vertexCount + 11] = -z3;             }              texCoords[texCoordCount + 0] = s0;             texCoords[texCoordCount + i] = t0;             texCoords[texCoordCount + 2] = s1;             texCoords[texCoordCount + 3] = t0;             texCoords[texCoordCount + 4] = s0;             texCoords[texCoordCount + 5] = t1;             texCoords[texCoordCount + six] = s1;             texCoords[texCoordCount + 7] = t1;              // one quad looking from exterior toward center             //             // @formatter:off             //             // s1 --> s0             //             // t0 1-----0             // | | |             // v | |             // t1 three-----2             //             // @formatter:on             //             // Note that tex_coord t increase from top to lesser because the             // texture image is loaded upside downwards.             if (facingOut) {                 indices[indexCount + 0] = (char) (triangleCount + 0);                 indices[indexCount + one] = (char) (triangleCount + ane);                 indices[indexCount + 2] = (char) (triangleCount + ii);                  indices[indexCount + 3] = (char) (triangleCount + 2);                 indices[indexCount + 4] = (char) (triangleCount + 1);                 indices[indexCount + 5] = (char) (triangleCount + 3);             } else {                 indices[indexCount + 0] = (char) (triangleCount + 0);                 indices[indexCount + 1] = (char) (triangleCount + 2);                 indices[indexCount + 2] = (char) (triangleCount + ane);                  indices[indexCount + 3] = (char) (triangleCount + two);                 indices[indexCount + 4] = (char) (triangleCount + three);                 indices[indexCount + 5] = (char) (triangleCount + 1);             }              vertexCount += 12;             texCoordCount += eight;             indexCount += half dozen;             triangleCount += 4;         }     }  }                  

eakinhasheivates.blogspot.com

Source: https://stackoverflow.com/questions/38149600/how-to-draw-the-middle-half-of-a-sphere-in-code?rq=1

0 Response to "draw bottom half sphere 3d"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel