示例#1
0
 /**
  * See the class documentation
  *
  * @param args - has no purpose
  */
 public static void main(String[] args) {
   boolean cont = true; // Whether or not the user wishes to continue
   while (cont) {
     double[] input = getInput();
     Sphere aSp = new Sphere(input[0]);
     Cylinder aCy = new Cylinder(input[0], input[1]);
     Cone aCo = new Cone(input[0], input[1]);
     System.out.println(
         "The VOLUME of a SPHERE of given specifications is: " + aSp.volume((int) input[2]));
     System.out.println(
         "The SURFACE AREA of a SPHERE of given specifications is: "
             + aSp.surfaceArea(((int) input[2])));
     System.out.println(
         "The VOLUME of a CYLINDER of given specifications is: " + aCy.volume(((int) input[2])));
     System.out.println(
         "The SURFACE AREA of a CYLINDER of given specifications is: "
             + aCy.surfaceArea(((int) input[2])));
     System.out.println(
         "The VOLUME of a CONE of given specifications is: " + aCo.volume(((int) input[2])));
     System.out.println(
         "The SURFACE AREA of a CONE of given specifications is: "
             + aCo.surfaceArea(((int) input[2])));
     try {
       Thread.sleep(1000);
     } catch (InterruptedException e) {
     }
     cont = getContinue();
   }
   sc.close();
 }
示例#2
0
 /**
  * Helper method
  *
  * @param c
  */
 public static void printStats(Cylinder c) {
   System.out.println("===");
   System.out.println("Radius: " + c.getRadius());
   System.out.println("Color: " + c.getColor());
   System.out.println("Height: " + c.getHeight());
   System.out.println("Base Area: " + c.getArea());
   System.out.println("Volume: " + c.getVolume());
   System.out.println("===");
 }
  public static void main(String args[]) {
    // the first value is the radius and the second value is the height
    Cylinder can = new Cylinder(3.0, 10.0);

    double surfaceArea, volume;

    surfaceArea =
        (2 * can.getRadius() * can.getHeight() * Math.PI)
            + (2 * Math.PI * Math.pow(can.getRadius(), 2));
    System.out.println("The surface area of a soda can is " + surfaceArea);

    volume = Math.PI * Math.pow(can.getRadius(), 2);
    System.out.println("The volume of a soda can is " + volume);
  } // ends main method
  private void drawBoundingVolumes(DrawContext dc, ArrayList<MercatorTextureTile> tiles) {
    float[] previousColor = new float[4];
    dc.getGL().glGetFloatv(GL.GL_CURRENT_COLOR, previousColor, 0);
    dc.getGL().glColor3d(0, 1, 0);

    for (MercatorTextureTile tile : tiles) {
      ((Cylinder) tile.getExtent(dc)).render(dc);
    }

    Cylinder c =
        dc.getGlobe()
            .computeBoundingCylinder(dc.getVerticalExaggeration(), this.levels.getSector());
    dc.getGL().glColor3d(1, 1, 0);
    c.render(dc);

    dc.getGL().glColor4fv(previousColor, 0);
  }
  public static String getLineXY(Cone cone, Cylinder cylinder) {
    double a1 = cylinder.getX();
    double a2 = cone.getX();
    double b1 = cylinder.getY();
    double b2 = cone.getY();
    double c2 = cone.getC();
    double r1 = cylinder.getR();
    double r2 = cone.getR();

    double x, y, z1, z2, s;
    x = 2 * (a2 - a1);
    y = 2 * (b2 - b1);
    z2 = (r2 * r2) / (c2 * c2);
    z1 = 2 * r2 * r2 / c2;
    s = r1 * r1 - r2 * r2 - a1 * a1 + a2 * a2 - b1 * b1 + b2 * b2;

    double xy, xz2, xz1, xs;
    xy = -y / x;
    xz2 = -z2 / x;
    xz1 = z1 / x;
    xs = s / x;

    return formulaToString("x = ", "y", xz2, xz1, xy, xs);
  }
示例#6
0
 // 总的绘制方法drawSelf
 public void drawSelf(int texId) {
   // 绘制交通柱的圆柱部分
   cone_in.drawSelf(texId);
   // 绘制交通柱下方底座的上面
   MatrixState.pushMatrix();
   MatrixState.translate(0, -UNIT_SIZE, 0);
   pedestal.drawSelf(texId);
   MatrixState.popMatrix();
   // 绘制交通柱下方底座的侧面
   MatrixState.pushMatrix();
   MatrixState.translate(0, -UNIT_SIZE - HEIGHT, 0);
   cylinder.drawSelf(texId);
   MatrixState.popMatrix();
   // 绘制交通柱下方底座的下面
   MatrixState.pushMatrix();
   MatrixState.translate(0, -UNIT_SIZE - HEIGHT * 2, 0);
   MatrixState.rotate(180, 1, 0, 0);
   pedestal.drawSelf(texId);
   MatrixState.popMatrix();
 }
  public static double[][] getTableZX(Cone cone, Cylinder cylinder, int count) {
    double a1 = cylinder.getX();
    double a2 = cone.getX();
    double b1 = cylinder.getY();
    double b2 = cone.getY();
    double c1 = cylinder.getC();
    double c2 = cone.getC();
    double r1 = cylinder.getR();
    double r2 = cone.getR();

    double x, z1, z2, s;
    x = 2 * (a2 - a1);
    z2 = (r2 * r2) / (c2 * c2);
    z1 = 2 * r2 * r2 / c2;
    s = r1 * r1 - r2 * r2 - a1 * a1 + a2 * a2 - b1 * b1 + b2 * b2;

    double xz2, xz1, xs;
    xz2 = -z2 / x;
    xz1 = z1 / x;
    xs = s / x;

    double coneLeftX = a2 + r2;
    double coneRightX = a2 - r2;
    double cylinderLeftX = a1 + r1;
    double cylinderRightX = a1 - r1;

    double leftX = min(coneLeftX, cylinderLeftX);
    double rightX = max(coneRightX, cylinderRightX);

    double z0 = 0;
    double maxZ = 0; // min(c1,c2);

    if (cylinderLeftX >= coneRightX && a2 >= cylinderLeftX) {
      maxZ = equationByTwoPoints(leftX, a2, c2, coneRightX, 0); // r
    }

    if (coneLeftX >= cylinderRightX && cylinderRightX >= a2) {
      maxZ = equationByTwoPoints(rightX, a2, c2, coneLeftX, 0); // l
    }

    if (coneLeftX >= cylinderLeftX && cylinderLeftX >= a2) {
      maxZ = equationByTwoPoints(leftX, a2, c2, coneLeftX, 0); // l
    }

    if (a2 >= cylinderRightX && cylinderRightX >= coneRightX) {
      maxZ = equationByTwoPoints(rightX, a2, c2, coneRightX, 0); // r
    }

    if (coneLeftX >= cylinderLeftX
        && cylinderLeftX >= a2
        && a2 > cylinderRightX
        && cylinderRightX > coneRightX) {

      z0 = equationByTwoPoints(rightX, a2, c2, coneRightX, 0); // r
      maxZ = equationByTwoPoints(leftX, a2, c2, coneLeftX, 0); // l
      maxZ -= z0;
    }

    if (a2 >= cylinderLeftX
        && a2 >= cylinderRightX
        && cylinderLeftX >= coneRightX
        && cylinderRightX >= coneRightX) {
      z0 = equationByTwoPoints(rightX, a2, c2, coneRightX, 0); // r
      maxZ = equationByTwoPoints(leftX, a2, c2, coneRightX, 0); // r
      maxZ -= z0;
    }

    if (coneLeftX >= cylinderLeftX
        && coneLeftX >= cylinderRightX
        && cylinderLeftX >= a2
        && cylinderRightX >= a2) {
      z0 = equationByTwoPoints(leftX, a2, c2, coneLeftX, 0); // l
      maxZ = equationByTwoPoints(rightX, a2, c2, coneLeftX, 0); // l
      maxZ -= z0;
    }

    double dZ = maxZ / count;
    double z = z0;

    double[][] result = new double[count + 1][2];

    for (int i = 0; i < count + 1; i++) {
      double x1 = xz2 * z * z + xz1 * z + xs;
      result[i][0] = z;
      result[i][1] = x1;
      z += dZ;
    }

    return result;
  }
示例#8
0
 public static void main(String[] argv) {
   Cylinder c = new Cylinder(3, 3, 2, 5);
   System.out.println(c.getVolumn());
 }
  public void render(GL2 gl2) {
    int i;

    boolean draw_finger_star = false;
    boolean draw_base_star = false;
    boolean draw_shoulder_to_elbow = false;
    boolean draw_shoulder_star = false;
    boolean draw_elbow_star = false;
    boolean draw_wrist_star = false;
    boolean draw_stl = true;

    // RebuildShoulders(motion_now);

    gl2.glPushMatrix();
    gl2.glTranslated(position.x, position.y, position.z);

    if (draw_stl) {
      // base
      gl2.glPushMatrix();
      gl2.glColor3f(0, 0, 1);
      gl2.glTranslatef(0, 0, BASE_TO_SHOULDER_Z + 0.6f);
      gl2.glRotatef(90, 0, 0, 1);
      gl2.glRotatef(90, 1, 0, 0);
      modelBase.render(gl2);
      gl2.glPopMatrix();

      // arms
      for (i = 0; i < 3; ++i) {
        gl2.glColor3f(1, 0, 1);
        gl2.glPushMatrix();
        gl2.glTranslatef(
            motion_now.arms[i * 2 + 0].shoulder.x,
            motion_now.arms[i * 2 + 0].shoulder.y,
            motion_now.arms[i * 2 + 0].shoulder.z);
        gl2.glRotatef(120.0f * i, 0, 0, 1);
        gl2.glRotatef(90, 0, 1, 0);
        gl2.glRotatef(180 - motion_now.arms[i * 2 + 0].angle, 0, 0, 1);
        modelArm.render(gl2);
        gl2.glPopMatrix();

        gl2.glColor3f(1, 1, 0);
        gl2.glPushMatrix();
        gl2.glTranslatef(
            motion_now.arms[i * 2 + 1].shoulder.x,
            motion_now.arms[i * 2 + 1].shoulder.y,
            motion_now.arms[i * 2 + 1].shoulder.z);
        gl2.glRotatef(120.0f * i, 0, 0, 1);
        gl2.glRotatef(90, 0, 1, 0);
        gl2.glRotatef(+motion_now.arms[i * 2 + 1].angle, 0, 0, 1);
        modelArm.render(gl2);
        gl2.glPopMatrix();
      }
      // top
      gl2.glPushMatrix();
      gl2.glColor3f(0, 1, 0);
      gl2.glTranslatef(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z);
      gl2.glRotatef(motion_now.iku, 1, 0, 0);
      gl2.glRotatef(motion_now.ikv, 0, 1, 0);
      gl2.glRotatef(motion_now.ikw, 0, 0, 1);
      gl2.glRotatef(90, 0, 0, 1);
      gl2.glRotatef(180, 1, 0, 0);
      modelTop.render(gl2);
      gl2.glPopMatrix();
    }

    // draw the forearms

    Cylinder tube = new Cylinder();
    gl2.glColor3f(0.8f, 0.8f, 0.8f);
    tube.setRadius(0.15f);
    for (i = 0; i < 6; ++i) {
      // gl2.glBegin(GL2.GL_LINES);
      // gl2.glColor3f(1,0,0);
      // gl2.glVertex3f(motion_now.arms[i].wrist.x,motion_now.arms[i].wrist.y,motion_now.arms[i].wrist.z);
      // gl2.glColor3f(0,1,0);
      // gl2.glVertex3f(motion_now.arms[i].elbow.x,motion_now.arms[i].elbow.y,motion_now.arms[i].elbow.z);
      // gl2.glEnd();
      tube.SetP1(motion_now.arms[i].wrist);
      tube.SetP2(motion_now.arms[i].elbow);
      PrimitiveSolids.drawCylinder(gl2, tube);
    }

    gl2.glDisable(GL2.GL_LIGHTING);
    // debug info
    gl2.glPushMatrix();
    for (i = 0; i < 6; ++i) {
      gl2.glColor3f(1, 1, 1);
      if (draw_shoulder_star) PrimitiveSolids.drawStar(gl2, motion_now.arms[i].shoulder, 5);
      if (draw_elbow_star) PrimitiveSolids.drawStar(gl2, motion_now.arms[i].elbow, 3);
      if (draw_wrist_star) PrimitiveSolids.drawStar(gl2, motion_now.arms[i].wrist, 1);

      if (draw_shoulder_to_elbow) {
        gl2.glBegin(GL2.GL_LINES);
        gl2.glColor3f(0, 1, 0);
        gl2.glVertex3f(
            motion_now.arms[i].elbow.x, motion_now.arms[i].elbow.y, motion_now.arms[i].elbow.z);
        gl2.glColor3f(0, 0, 1);
        gl2.glVertex3f(
            motion_now.arms[i].shoulder.x,
            motion_now.arms[i].shoulder.y,
            motion_now.arms[i].shoulder.z);
        gl2.glEnd();
      }
    }
    gl2.glPopMatrix();

    if (draw_finger_star) {
      // draw finger orientation
      float s = 2;
      gl2.glBegin(GL2.GL_LINES);
      gl2.glColor3f(1, 1, 1);
      gl2.glVertex3f(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z);
      gl2.glVertex3f(
          motion_now.finger_tip.x + motion_now.finger_forward.x * s,
          motion_now.finger_tip.y + motion_now.finger_forward.y * s,
          motion_now.finger_tip.z + motion_now.finger_forward.z * s);
      gl2.glVertex3f(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z);
      gl2.glVertex3f(
          motion_now.finger_tip.x + motion_now.finger_up.x * s,
          motion_now.finger_tip.y + motion_now.finger_up.y * s,
          motion_now.finger_tip.z + motion_now.finger_up.z * s);
      gl2.glVertex3f(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z);
      gl2.glVertex3f(
          motion_now.finger_tip.x + motion_now.finger_left.x * s,
          motion_now.finger_tip.y + motion_now.finger_left.y * s,
          motion_now.finger_tip.z + motion_now.finger_left.z * s);

      gl2.glEnd();
    }

    if (draw_base_star) {
      // draw finger orientation
      float s = 2;
      gl2.glDisable(GL2.GL_DEPTH_TEST);
      gl2.glBegin(GL2.GL_LINES);
      gl2.glColor3f(1, 0, 0);
      gl2.glVertex3f(motion_now.base.x, motion_now.base.y, motion_now.base.z);
      gl2.glVertex3f(
          motion_now.base.x + motion_now.base_forward.x * s,
          motion_now.base.y + motion_now.base_forward.y * s,
          motion_now.base.z + motion_now.base_forward.z * s);
      gl2.glColor3f(0, 1, 0);
      gl2.glVertex3f(motion_now.base.x, motion_now.base.y, motion_now.base.z);
      gl2.glVertex3f(
          motion_now.base.x + motion_now.base_up.x * s,
          motion_now.base.y + motion_now.base_up.y * s,
          motion_now.base.z + motion_now.base_up.z * s);
      gl2.glColor3f(0, 0, 1);
      gl2.glVertex3f(motion_now.base.x, motion_now.base.y, motion_now.base.z);
      gl2.glVertex3f(
          motion_now.base.x + motion_now.finger_left.x * s,
          motion_now.base.y + motion_now.finger_left.y * s,
          motion_now.base.z + motion_now.finger_left.z * s);

      gl2.glEnd();
      gl2.glEnable(GL2.GL_DEPTH_TEST);
    }

    gl2.glEnable(GL2.GL_LIGHTING);

    gl2.glPopMatrix();
  }
 public static double calculateCylinderVolume(Cylinder cylinder) {
   return Math.PI * Math.pow(cylinder.getRadius(), 2) * cylinder.getHeight();
 }
 @Test
 public void isCorrectCalculationCylinderSquareWithZeroValue() {
   Cylinder figure = new Cylinder(0, 0);
   assertEquals(0, figure.calculateSquare(), DELTA);
 }
 @Test
 public void isCorrectCalculationCylinderSquareWithRealValues() {
   Cylinder figure = new Cylinder(1.0, 1.0);
   assertEquals(4 * Math.PI, figure.calculateSquare(), DELTA);
 }
 @Test
 public void isCorrectCalculationCylinderSquareWithIntegerValue() {
   Cylinder figure = new Cylinder(1, 1);
   assertEquals(4 * Math.PI, figure.calculateSquare(), DELTA);
 }
示例#14
0
 protected void initialize(DrawContext dc) {
   super.initialize(dc);
   this.name = "Pipe";
 }
示例#15
0
  public static void main(String[] args) {
    Cylinder c1 = new Cylinder(); // no-arg constructor
    System.out.println(
        "cylinder #1 properties:\n"
            + "radius = "
            + c1.getRadius()
            + "\n"
            + "height = "
            + c1.getHeight()
            + "\n"
            + "base area = "
            + c1.getBaseArea()
            + "\n"
            + "surface area = "
            + c1.getArea()
            + "\n"
            + "volume = "
            + c1.getVolume()
            + "\n"
            + c1.toString()
            + "\n");

    Cylinder c2 = new Cylinder(10.0); // one-arg constructor
    System.out.println(
        "cylinder #2 properties:\n"
            + "radius = "
            + c2.getRadius()
            + "\n"
            + "height = "
            + c2.getHeight()
            + "\n"
            + "base area = "
            + c2.getBaseArea()
            + "\n"
            + "surface area = "
            + c2.getArea()
            + "\n"
            + "volume = "
            + c2.getVolume()
            + "\n"
            + c2.toString()
            + "\n");

    Cylinder c3 = new Cylinder(2.0, 10.0); // two-arg constructor
    System.out.println(
        "cylinder #3 properties:\n"
            + "radius = "
            + c3.getRadius()
            + "\n"
            + "height = "
            + c3.getHeight()
            + "\n"
            + "base area = "
            + c3.getBaseArea()
            + "\n"
            + "surface area = "
            + c3.getArea()
            + "\n"
            + "volume = "
            + c3.getVolume()
            + "\n"
            + c3.toString());
  }