0

I have a 40x40 array filled with double values that correspond to a mesh grid composed of 2 matrices in Java. I would like to plot a surface out of those values in 3D, and found JZY3D library that seems appropriate, but I don't know where to start and how to code this kind of plot. Anyone worked with this library and can give a good advice on where to start ?

Community
  • 1
  • 1
borgmater
  • 658
  • 3
  • 11
  • 35

1 Answers1

2

It seems like jzy3D's SurfaceDemo. You need to create surface rather than buildOrthonormal(Line 36 in SurfaceDemo.java).

ans: https://stackoverflow.com/a/8339474

Algorithms: https://www.mathworks.com/help/matlab/ref/surf.html

double[][] Z = new double[40][40];
...
List<Polygon> polygons = new ArrayList<Polygon>();
for(int i = 0; i < zq.length -1; i++){
    for(int j = 0; j < zq[0].length -1; j++){
        Polygon polygon = new Polygon();
        polygon.add(new Point(new Coord3d(i, j, Z[i][j])));
        polygon.add(new Point(new Coord3d(i, j+1, Z[i][j+1])));
        polygon.add(new Point(new Coord3d(i+1, j+1, Z[i+1][j+1])));
        polygon.add(new Point(new Coord3d(i+1, j, Z[i+1][j])));
        polygons.add(polygon);
    }
}
final Shape surface = new Shape(polygons);
surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface.getBounds().getZmin(), surface.getBounds().getZmax(), new Color(1, 1, 1, .5f)));
surface.setFaceDisplayed(true);
surface.setWireframeDisplayed(true);
// Create a chart and add it
Chart chart = new Chart();
chart.getAxeLayout().setMainColor(Color.WHITE);
chart.getView().setBackgroundColor(Color.BLACK);
chart.getScene().add(surface);
ChartLauncher.openChart(chart);

result

Community
  • 1
  • 1
kurt
  • 21
  • 3
  • Thank you for your answer but seems like I wont be using this library, because the maven repository needs to be added to the remote server for which i have no permission, unfortunately :-/ Do you maybe have an advice on how to perform plotting with another library ? – borgmater Oct 13 '16 at 07:55