plotgraphinterpolationjzy3d

Jzy3d 3d interpolation plots not rendering


I am trying to plot a 3d path given a set of coordinates. From jzy3d's demo application, I've found that this is possible through their BernsteinInterpolator and LineStripInterpolated classes.

With the help of their source code, my attempt to reproduce this is as follows:

public static void main(String[] args) {

    BernsteinInterpolator interp = new BernsteinInterpolator();

    List<Coord3d> controlCoords = new ArrayList<>();
    controlCoords.add(new Coord3d(0.0, 0.0, 0.0));        
    controlCoords.add(new Coord3d(1.0, 0.0, 1.0));
    controlCoords.add(new Coord3d(1.0, 0.0, 2.0));
    controlCoords.add(new Coord3d(1.0, 1.0, 2.0));
    controlCoords.add(new Coord3d(0.0, 1.0, 2.0));
    controlCoords.add(new Coord3d(3.0, 2.0, -1.0));

    LineStripInterpolated line = new LineStripInterpolated(interp, controlCoords, 30);

    Chart chart = new AWTChart(Quality.Intermediate);
    chart.add(line);
    chart.open("chart test", 600, 600);
}

This is what I would expect to get, according to the demo application -> DemoPlot

Unfortunately, the above only renders a blank window with no errors or exceptions. Does anyone have any idea what went wrong? Your help is greatly appreciated!


Solution

  • So I digged a little deeper into the source code and found that there is a way to bypass the LineStripInterpolated class as follows:

    public static void main(String[] args) {
    
        List<Coord3d> controlCoords = new ArrayList<>();
        controlCoords.add(new Coord3d(0.0F, 0.0F, 0.0F));
        controlCoords.add(new Coord3d(1.0F, 0.0F, 1.0F));
        controlCoords.add(new Coord3d(1.0F, 0.0F, 2.0F));
        controlCoords.add(new Coord3d(1.0F, 1.0F, 2.0F));
        controlCoords.add(new Coord3d(0.0F, 1.0F, 2.0F));
        controlCoords.add(new Coord3d(3.0F, 2.0F, -1.0F));
    
        BernsteinInterpolator interp = new BernsteinInterpolator();
        List<Coord3d> interpolatedCoords = interp.interpolate(controlCoords, 30);
    
        List<Point> controlPoints = new ArrayList<>();
        for (Coord3d coord : controlCoords) {
            controlPoints.add(new Point(coord, Color.RED, 5.0));
        }
    
        List<Point> interpPoints = new ArrayList<>();
        for (Coord3d coord : interpolatedCoords) {
            interpPoints.add(new Point(coord, Color.BLUE, 3.0));
        }
    
        LineStrip line = new LineStrip(interpolatedCoords);
        line.setWireframeColor(Color.BLACK);
    
        Chart chart = new AWTChart(Quality.Intermediate);
        chart.add(line);
        chart.add(controlPoints);
        chart.add(interpPoints);
        chart.open("chart test", 600, 600);
    }
    

    Hope this helps anyone else with the same problem. I'm still curious as to why my previous method didn't work though. :(