【问题标题】:Draw Lorenz attractor from Point3f array in Java 3D从 Java 3D 中的 Point3f 数组中绘制 Lorenz 吸引子
【发布时间】:2012-05-16 00:35:45
【问题描述】:

我已经计算了需要绘制的点的值,并将它们放入 Point3f 数组中。我有 526 435 分。下一步是一个接一个地绘制点,使其看起来像一条连续的线,或者使用 LineStripArray 在点之间绘制线。因为没有找到如何逐点绘制,所以尝试使用 LineStripArray。

我已从here 获取代码,并使用以下代码更改了“createLineTypes”方法的内容:

    Group lineGroup = new Group();

    Appearance app = new Appearance();
    ColoringAttributes ca = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT);
    app.setColoringAttributes(ca);

    Computing comp = new Computing();

    //the following row computes the values of the points I want to draw 
    //and it works alright; the points are saved into 
    //**static List<Vector3> computed_values** from  class Computing,
    // where Vector3 class defines a 3D point actually
    comp.do_the_job();    

    Point3f[] dashPts = new Point3f[Computing.computed_values.size()];
    for(int i = 0; i < Computing.computed_values.size(); i++)
    {
        dashPts[i] = new Point3f((int)Computing.computed_values.get(i).getX(), (int)Computing.computed_values.get(i).getY(), (int)Computing.computed_values.get(i).getZ());

    }
    System.out.print(Computing.computed_values.size());
    int[] a = {Computing.computed_values.size()};
    LineStripArray dash = new LineStripArray(Computing.computed_values.size(), LineArray.COORDINATES, a);
    dash.setCoordinates(0, dashPts);
    LineAttributes dashLa = new LineAttributes();
    dashLa.setLineWidth(1.0f);
    dashLa.setLinePattern(LineAttributes.PATTERN_SOLID);
    Shape3D dashShape = new Shape3D(dash, app);
    lineGroup.addChild(dashShape);


    return lineGroup;

问题是它只画了 1 条垂直线。有什么想法吗?

【问题讨论】:

    标签: java graphics 3d drawing java-3d


    【解决方案1】:

    我找到了一个解决方案,它使用 PointArray。在这里

        Group lineGroup = new Group();
    
        Appearance app = new Appearance();
        ColoringAttributes ca = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT);
        app.setColoringAttributes(ca);
    
        Computing comp = new Computing();
        comp.do_the_job();
    
        Point3f[] plaPts = new Point3f[Computing.computed_values.size()];
        for(int i = 0; i < Computing.computed_values.size(); i++)
        {           
            plaPts[i] = new Point3f((float)Computing.computed_values.get(i).getX(), (float)Computing.computed_values.get(i).getY(), (float)Computing.computed_values.get(i).getZ());            
        }
    
        PointArray pla = new PointArray(Computing.computed_values.size(), GeometryArray.COORDINATES);
        pla.setCoordinates(0, plaPts);
        Shape3D plShape = new Shape3D(pla, app);
        lineGroup.addChild(plShape);
    
        return lineGroup;
    

    重要提示:对于我的应用程序,我必须将值转换为 float,而不是像最初那样转换为 int。

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-01
      • 1970-01-01
      • 2021-05-05
      • 2011-10-23
      相关资源
      最近更新 更多