예제 #1
0
  public void plot(AbstractDrawer draw, Color c) {
    if (!visible) return;

    int cor = 0;
    for (int j = 0; j < z.length; j++) {
      if (j < z.length / 2) {
        color = new Color(0, j * (255 / (z.length / 2)), 255);
        cor = j;
      } else {
        color = new Color(255, cor * (255 / (z.length / 2)), 0);
        cor = (cor == 0) ? cor : cor - 1;
      }

      Cone _cone = new Cone(k, color);
      double h = height - j * 0.1;
      double r = ratio * (h / height); // semelhança de triangulos

      for (int i = 0; i < k + 1; i++) {
        _cone.setCone(i, r * Math.cos(i * theta), r * Math.sin(i * theta), z[j]);
      }
      listCone.add(j, _cone);
    }
    // Para saber se a visão do gráfico é superior, basta saber se screenCoord[1] <= 333. Do
    // contrário, estamos vendo o gráfico por baixo.
    int[] screenCoord = draw.project(new double[] {-1, -1, -1});

    if (screenCoord[1] <= 333) {
      for (int i = 1; i < listCone.size(); i++) {
        for (int j = 1; j < k + 1; j++) {
          draw.setColor(listCone.get(i).getColor());
          draw.fillPolygon(
              1.0f,
              new double[] {
                listCone.get(i).getX(j), listCone.get(i).getY(j), listCone.get(i).getZ(j)
              },
              new double[] {
                listCone.get(i).getX(j - 1), listCone.get(i).getY(j - 1), listCone.get(i).getZ(j)
              },
              new double[] {
                listCone.get(i - 1).getX(j - 1),
                listCone.get(i - 1).getY(j - 1),
                listCone.get(i - 1).getZ(j - 1)
              },
              new double[] {
                listCone.get(i - 1).getX(j),
                listCone.get(i - 1).getY(j),
                listCone.get(i - 1).getZ(j - 1)
              });

          draw.setColor(new Color(0, 0, 0));
          draw.drawPolygon(
              new double[] {
                listCone.get(i).getX(j), listCone.get(i).getY(j), listCone.get(i).getZ(j)
              },
              new double[] {
                listCone.get(i).getX(j - 1), listCone.get(i).getY(j - 1), listCone.get(i).getZ(j)
              },
              new double[] {
                listCone.get(i - 1).getX(j - 1),
                listCone.get(i - 1).getY(j - 1),
                listCone.get(i - 1).getZ(j - 1)
              },
              new double[] {
                listCone.get(i - 1).getX(j),
                listCone.get(i - 1).getY(j),
                listCone.get(i - 1).getZ(j - 1)
              });
        }
      }

    } else {
      for (int i = listCone.size() - 1; i > 0; i--) {
        for (int j = 1; j < k + 1; j++) {
          draw.setColor(listCone.get(i).getColor());
          draw.fillPolygon(
              1.0f,
              new double[] {
                listCone.get(i).getX(j), listCone.get(i).getY(j), listCone.get(i).getZ(j)
              },
              new double[] {
                listCone.get(i).getX(j - 1), listCone.get(i).getY(j - 1), listCone.get(i).getZ(j)
              },
              new double[] {
                listCone.get(i - 1).getX(j - 1),
                listCone.get(i - 1).getY(j - 1),
                listCone.get(i - 1).getZ(j - 1)
              },
              new double[] {
                listCone.get(i - 1).getX(j),
                listCone.get(i - 1).getY(j),
                listCone.get(i - 1).getZ(j - 1)
              });

          draw.setColor(new Color(0, 0, 0));
          draw.drawPolygon(
              new double[] {
                listCone.get(i).getX(j), listCone.get(i).getY(j), listCone.get(i).getZ(j)
              },
              new double[] {
                listCone.get(i).getX(j - 1), listCone.get(i).getY(j - 1), listCone.get(i).getZ(j)
              },
              new double[] {
                listCone.get(i - 1).getX(j - 1),
                listCone.get(i - 1).getY(j - 1),
                listCone.get(i - 1).getZ(j - 1)
              },
              new double[] {
                listCone.get(i - 1).getX(j),
                listCone.get(i - 1).getY(j),
                listCone.get(i - 1).getZ(j - 1)
              });
        }
      }
    }
    listCone.clear();
  }