Skip to content

Instantly share code, notes, and snippets.

@thorstenwagner
Last active April 19, 2016 11:26
Show Gist options
  • Save thorstenwagner/051868fea176d9e208509805a081b009 to your computer and use it in GitHub Desktop.
Save thorstenwagner/051868fea176d9e208509805a081b009 to your computer and use it in GitHub Desktop.
Weierstrass-Mandelbrot
public Trajectory generateTrajectory() {
Trajectory t = new Trajectory(dimension);
t.add(new Point3d(0, 0, 0));
double[] incrx = generateIncrements();
double[] incry = generateIncrements();
for(int i = 1; i <= numberOfSteps; i++) {
Point3d pos = new Point3d();
pos.setX(t.get(i-1).x + incrx[i-1]);
pos.setY(t.get(i-1).y + incry[i-1]);
t.add(pos);
}
return t;
}
public double[] generateIncrements(){
double gamma = Math.sqrt(Math.PI);
double H = alpha/2;
double[] wxs = new double[numberOfSteps];
double[] increments = new double[numberOfSteps];
double[] phasesx = new double[48+8+1];
for(int j = 0; j < phasesx.length; j++){
phasesx[j] = CentralRandomNumberGenerator.getInstance().nextDouble()*2*Math.PI;
}
for(int t = 1; t <= numberOfSteps; t++){
double tStar = 2*Math.PI*t/numberOfSteps;
double wx = 0;
for(int n = -8; n <= 48; n++){
double phasex = phasesx[n+8];
wx += (Math.cos(phasex)-Math.cos(Math.pow(gamma, n) * tStar + phasex))/Math.pow(gamma, n*H);
}
double prevwx = (t-2)>=0?wxs[t-2]:0;
wxs[t-1] = wx;
increments[t-1] = wxs[t-1]-prevwx;
}
return increments;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment