简体   繁体   中英

Build a 3d surface plot using xyz coordinates with jzy3d

I've been searching for a way to send a list of coord(x,y,z) to jzy3d. But without success.

The only way I found is to use a "builder" with a list of "coord3d" and a "tesselator", but it actually doesn't work.

I don't realy get the meaning of the Tesselator in fact ?

Here is the code I tried :

public Chart getChart(){

    List<Coord3d> coordinates = new ArrayList<Coord3d>();
    for(int i=0; i<200; i++)
        coordinates.add( new Coord3d(5, 10, 15) );
    Tesselator tesselator = new Tesselator() {          
        @Override
        public AbstractComposite build(float[] x, float[] y, float[] z) {
            return null;
        }
    };      
    tesselator.build(coordinates);
     org.jzy3d.plot3d.primitives.Shape surface = (Shape)Builder.build(coordinates, tesselator);


/*/ Define a function to plot
  Mapper mapper = new Mapper(){
     public double f(double x, double y) {
        return 10*Math.sin(x/10)*Math.cos(y/20)*x;
     }
  };*/

  // Define range and precision for the function to plot
 // Range range = new Range(-150,150);
 // int steps   = 50;

  // Create the object to represent the function over the given range.
 // org.jzy3d.plot3d.primitives.Shape surface = (Shape)Builder.buildOrthonormal(new OrthonormalGrid(range, steps, range, steps), mapper);
  //surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface.getBounds().getZmin(), surface.getBounds().getZmax(), new Color(1,1,1,.5f)));
 // surface.setWireframeDisplayed(true);
//  surface.setWireframeColor(Color.BLACK);
  //surface.setFace(new ColorbarFace(surface));
  //surface.setFaceDisplayed(true);
  //surface.setFace2dDisplayed(true); // opens a colorbar on the right part of the display

  // Create a chart
  Chart chart = new Chart("swing");
  chart.getScene().getGraph().add(surface);
  return chart;
}

Could someone please tell me how to feed my graph with many XYZ coordonates so that I may get a 3d surface plot like this one :

3D表面图
(source: free.fr )

A tesselator allows creating polygons out of a list of points. Jzy3d provides two base tesselators: one that supports points standing on a regular grid (called OrthonormalTesselator), one that supports unstructured points as input (DelaunayTesselator). The second one is not always "working good": not a problem concerning its implementation but mainly the fact that it's difficult to decide how points should work together to form a polygon in 3d. You may find some discussions about it on Jzy3d wiki and discussion groups.

To manually build polygons, here's what you should do:

// Build a polygon list
    double [][]distDataProp = new double[][] {{.25,.45, .20},{.56, .89, .45}, {.6, .3,.7}};
    List<Polygon> polygons = new ArrayList<Polygon>();
    for(int i = 0; i < distDataProp.length -1; i++){
        for(int j = 0; j < distDataProp[i].length -1; j++){
            Polygon polygon = new Polygon();
            polygon.add(new Point( new Coord3d(i, j, distDataProp[i][j]) ));
            polygon.add(new Point( new Coord3d(i, j+1, distDataProp[i][j+1]) ));
            polygon.add(new Point( new Coord3d(i+1, j+1, distDataProp[i+1][j+1]) ));
            polygon.add(new Point( new Coord3d(i+1, j, distDataProp[i+1][j]) ));
            polygons.add(polygon);
        }
    }

    // Creates the 3d object
    Shape surface = new Shape(polygons);
    surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface.getBounds().getZmin(), surface.getBounds().getZmax(), new org.jzy3d.colors.Color(1,1,1,1f)));
    surface.setWireframeDisplayed(true);
    surface.setWireframeColor(org.jzy3d.colors.Color.BLACK);

    chart = new Chart();
    chart.getScene().getGraph().add(surface);

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