예제 #1
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);
  }
예제 #2
0
  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;
  }