Search code examples
javagraphics3ddrawingjava-3d

Draw Lorenz attractor from Point3f array in Java 3D


I have computed the values of the points I need to draw and I put them in a Point3f array. I have 526 435 points. The next step is to draw the points one after another so that it would look like a continous line OR to draw lines between the points using LineStripArray. Because I didn't find how to draw point by point, I've tried to use LineStripArray.

I've taken the code from here and I've changed the content of the method "createLineTypes" with the following code:

    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;

The problem is that it only draws 1 vertical line. Any ideas?


Solution

  • I've found a solution and it's with PointArray. Here it is

        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;
    

    Important: for my application, I had to cast the values to float, not to int as I initially did.