简体   繁体   中英

Plotting mesh grid surface in Java

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM