简体   繁体   中英

Simple scatter plotter with Jzy3d (Java)

I'm trying to write a plotter class to display a set of data points (x, y, z) stored in an array using Jzy3d . The class should contain a method plot() that takes the data set and (automatically) displays it in a 3d coordinate system.
The method is supposed to be called sequentially in a time-dependent loop.

So far I have managed get a scatter plot demo for Jzy3d working but I don't know what each bit of the code does. The documentation of Jzy3d doesn't provide that much information and I can't really to find any tutorials online.

It would be much appreciated if anyone can explain the demo or (even better) write a simple plotter that contains a similar method.

Any efficient working plotting alternatives to Jzy3d would be appreciated, too.

Demo code:

import java.util.Random;

import org.jzy3d.analysis.AbstractAnalysis;
import org.jzy3d.analysis.AnalysisLauncher;
import org.jzy3d.chart.factories.AWTChartComponentFactory;
import org.jzy3d.colors.Color;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.plot3d.primitives.Scatter;
import org.jzy3d.plot3d.rendering.canvas.Quality;


public class ScatterDemo extends AbstractAnalysis{
    public static void main(String[] args) throws Exception {
        AnalysisLauncher.open(new ScatterDemo());
    }

    @Override
    public void init(){
        int size = 500000;
        float x;
        float y;
        float z;
        float a;

        Coord3d[] points = new Coord3d[size];
        Color[]   colors = new Color[size];

        Random r = new Random();
        r.setSeed(0);

        for(int i=0; i<size; i++){
            x = r.nextFloat() - 0.5f;
            y = r.nextFloat() - 0.5f;
            z = r.nextFloat() - 0.5f;
            points[i] = new Coord3d(x, y, z);
            a = 0.25f;
            colors[i] = new Color(x, y, z, a);
        }

        Scatter scatter = new Scatter(points, colors);
        chart = AWTChartComponentFactory.chart(Quality.Advanced, "newt");
        chart.getScene().add(scatter);
    }
}

this method should create new scatter

public void plot(Coord3d[] points, Color[]   colors) {
    Scatter scatter = new Scatter(points, colors);
    chart = AWTChartComponentFactory.chart(Quality.Advanced, "newt");
    chart.getScene().add(scatter);
}

this code shows how to create dataset, just use your values of coordinates and color

int size = 100
Coord3d[] points = new Coord3d[size];
Color[]   colors = new Color[size];  
for(int i=0; i < size; i++){
        x = i;
        y = i;
        z = i;
        points[i] = new Coord3d(x, y, z);

        r = 0.5;
        b = 0.5;
        g = 0.5;
        colors[i] = new Color(r, g, b);
    }

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