使用jzy3d生成基于xyz坐标的3D表面图

3
我一直在寻找一种将坐标列表(x,y,z)发送到jzy3d的方法,但没有成功。
我唯一找到的方法是使用一个“builder”,其中包含一个“coord3d”列表和一个“tesselator”,但实际上并不起作用。
实际上,我并不明白Tesselator的意义是什么?
以下是我尝试过的代码:
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;
}

请问如何用多个XYZ坐标来填充我的图形,以便像这样得到一个三维表面图:A 3d surface plot(图片来源:free.fr
1个回答

5
一个tesselator可以将点列表创建成多边形。Jzy3d提供了两个基本的tesselators:一个支持在规则网格上放置的点(称为OrthonormalTesselator),另一个支持非结构化点作为输入(DelaunayTesselator)。第二个不总是“工作良好”的:这不是关于其实现的问题,而主要是因为很难决定如何使点在三维中一起形成多边形。您可以在Jzy3d wiki和讨论组中找到一些讨论。

要手动构建多边形,您应该执行以下操作:

// 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);

它完美地运行了。这正是我想要做的!非常感谢你! - Jsncrdnl
如果我想在这里使用Fxyz3d而不是Jzy3d包来做同样的事情,该怎么办? - blessedk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接