00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00032 public class FastFractal {
00033
00034 private UnitFunction1D unitFunction;
00035 private int dimensions;
00036 private FractalFunction1D ff;
00037
00049 public FastFractal (String unitFunctionName, int fractalDepth, int density, long index, int dimensions) throws Exception {
00050 unitFunction = (UnitFunction1D) Class.forName(unitFunctionName).newInstance();
00051 this.dimensions = dimensions;
00052 ff = new FractalFunction1D(unitFunction, fractalDepth, density, index);
00053 }
00054
00062 public double evaluate (double[] point) {
00063 if (point.length != dimensions) throw new RuntimeException("Point does not have "+dimensions+" dimensions.");
00064 double depth = 0;
00065 double x, lastx, dx;
00066 ff.setIndex((6*dimensions-1)+1);
00067 lastx = point[dimensions-1];
00068 for (int i=0; i<dimensions; i++) {
00069 ff.setIndex(6*i+1);
00070 x = point[i];
00071 dx = unitFunction.twist(x,lastx);
00072 depth = depth + ff.evaluate(x+dx);
00073 lastx = x;
00074 }
00075 return depth;
00076 }
00077
00084 public double[] evaluate (double[][] points) {
00085 if (points[0].length != dimensions) throw new RuntimeException("Point does not have "+dimensions+" dimensions.");
00086 double[] results = new double[points.length];
00087 for (int i=0; i<points.length; i++) results[i] = evaluate(points[i]);
00088 return results;
00089 }
00090
00091 }
00092
00093