-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMandelbrotMath.java
More file actions
56 lines (46 loc) · 1.29 KB
/
MandelbrotMath.java
File metadata and controls
56 lines (46 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package mandelbrotSet;
import java.util.concurrent.Callable;
import org.apfloat.Apfloat;
public class MandelbrotMath implements Callable<double[]> {
private static final double log2 = Math.log(2);
private int max, col, row;
private Apfloat real;
private Apfloat imagine;
public MandelbrotMath(int max, Apfloat real, Apfloat imagine, int row, int col) {
this.max = max;
this.col = col;
this.row = row;
this.real = real;
this.imagine = imagine;
}
@Override
public double[] call() throws Exception {
double[] pixel = new double[3];
pixel[0] = calcPixel();
pixel[1] = row;
pixel[2] = col;
return pixel;
}
private double calcPixel() {
Apfloat x = new Apfloat(0, 100);
Apfloat y = new Apfloat(0, 100);
Apfloat xSqr = new Apfloat(0, 100);
Apfloat ySqr = new Apfloat(0, 100);
int iteration = 0;
while (xSqr.add(ySqr).compareTo(new Apfloat(4)) < 0 && iteration < max) {
xSqr = x.multiply(x);
ySqr = y.multiply(y);
Apfloat xTemp = xSqr.subtract(ySqr).add(real);
y = x.multiply(new Apfloat(2)).multiply(y).add(imagine);
x = xTemp;
iteration++;
}
if (iteration == max) {
return iteration;
} else {
double logZn = Math.log(xSqr.doubleValue() + ySqr.doubleValue()) / 2;
double nu = Math.log(logZn / log2) / log2;
return iteration + 1 - nu;
}
}
}