diff --git a/jzy3d-api/src/api/org/jzy3d/plot3d/builder/concrete/WaterfallTessellator.java b/jzy3d-api/src/api/org/jzy3d/plot3d/builder/concrete/WaterfallTessellator.java index 85aa7b50..1d479d00 100644 --- a/jzy3d-api/src/api/org/jzy3d/plot3d/builder/concrete/WaterfallTessellator.java +++ b/jzy3d-api/src/api/org/jzy3d/plot3d/builder/concrete/WaterfallTessellator.java @@ -9,6 +9,11 @@ import org.jzy3d.plot3d.primitives.Shape; import org.jzy3d.plot3d.primitives.TesselatedPolygon; import org.jzy3d.plot3d.primitives.WaterfallComposite; +/** + * Build a drawable Waterfall using Matlab style + * + * @author Jacob Filik + */ public class WaterfallTessellator extends Tessellator { @Override diff --git a/jzy3d-api/src/api/org/jzy3d/plot3d/primitives/WaterfallComposite.java b/jzy3d-api/src/api/org/jzy3d/plot3d/primitives/WaterfallComposite.java index 08c4e898..fa67a4b7 100644 --- a/jzy3d-api/src/api/org/jzy3d/plot3d/primitives/WaterfallComposite.java +++ b/jzy3d-api/src/api/org/jzy3d/plot3d/primitives/WaterfallComposite.java @@ -5,6 +5,13 @@ import java.util.List; import org.jzy3d.colors.Color; import org.jzy3d.colors.ColorMapper; +/** + * A drawable Waterfall using Matlab style + * + * @see WaterfallTessellator + * + * @author Jacob Filik + */ public class WaterfallComposite extends Shape { public void add(ColoredWireframePolygon outline, Shape fill) { diff --git a/jzy3d-tutorials/src/main/java/org/jzy3d/demos/waterfall/WaterfallDemo.java b/jzy3d-tutorials/src/main/java/org/jzy3d/demos/waterfall/WaterfallDemo.java index 24b5d10b..d048cf1a 100644 --- a/jzy3d-tutorials/src/main/java/org/jzy3d/demos/waterfall/WaterfallDemo.java +++ b/jzy3d-tutorials/src/main/java/org/jzy3d/demos/waterfall/WaterfallDemo.java @@ -18,46 +18,43 @@ public class WaterfallDemo extends AbstractAnalysis { @Override public void init() { - float[] x = new float[80]; - - for (int i = 0; i < x.length; i++) { - x[i] = -3f + 6f*((float)i/(x.length-1)); - } - - float[] y = new float[40]; - - for (int i = 0; i < y.length; i++) { - y[i] = -3f + 2f*((float)i/(y.length-1)); - } - - float[] z = getZ(x,y); + float[] x = new float[80]; + + for (int i = 0; i < x.length; i++) { + x[i] = -3f + 6f * ((float) i / (x.length - 1)); + } + + float[] y = new float[40]; + + for (int i = 0; i < y.length; i++) { + y[i] = -3f + 2f * ((float) i / (y.length - 1)); + } + + float[] z = getZ(x, y); + + WaterfallTessellator waterfall = new WaterfallTessellator(); + + Shape build = waterfall.build(x, y, z); + build.setColorMapper(new ColorMapper(new ColorMapRainbow(), build.getBounds().getZmin(), build.getBounds().getZmax(), new Color(1, 1, 1, .5f))); - WaterfallTessellator waterfall = new WaterfallTessellator(); - - Shape build =waterfall.build(x, y, z); - build.setColorMapper(new ColorMapper(new ColorMapRainbow(), build.getBounds().getZmin(), build.getBounds().getZmax(), new Color(1, 1, 1, .5f))); -// build.setColor(Color.BLACK); // Create a chart chart = AWTChartComponentFactory.chart(Quality.Intermediate, getCanvasType()); chart.getScene().getGraph().add(build); chart.getView(); } - + private float[] getZ(float[] x, float[] y) { + float[] z = new float[x.length * y.length]; - float[] z = new float[x.length*y.length]; - - for (int i = 0; i < y.length; i++) { - for (int j = 0; j < x.length; j++) { - z[j + (x.length*i)] = (float)f((double)x[j],(double)y[i]); - } - } - - return z; - + for (int i = 0; i < y.length; i++) { + for (int j = 0; j < x.length; j++) { + z[j + (x.length * i)] = (float) f((double) x[j], (double) y[i]); + } + } + return z; } private double f(double x, double y) { - return x * Math.sin(x * y); + return x * Math.sin(x * y); } } \ No newline at end of file