KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > chaos > JuliaSet


1 package JSci.maths.chaos;
2
3 import JSci.maths.Complex;
4
5 /**
6 * The JuliaSet class provides an object that encapsulates Julia sets.
7 * @version 1.0
8 * @author Mark Hale
9 */

10 public final class JuliaSet extends Object JavaDoc {
11         public final static Complex RABBIT=new Complex(-0.123,0.745);
12         public final static Complex SAN_MARCO=new Complex(-0.75,0.0);
13         public final static Complex SIEGEL_DISK=new Complex(-0.391,-0.587);
14         private final MandelbrotMap mbrot;
15         /**
16         * Constructs a Julia set.
17         */

18         public JuliaSet(Complex c) {
19                 mbrot=new MandelbrotMap(c);
20         }
21         /**
22         * Returns 0 if z is a member of this set,
23         * else the number of iterations it took for z to diverge to infinity.
24         */

25         public int isMember(Complex z,final int maxIter) {
26                 for(int i=0;i<maxIter;i++) {
27                         z=mbrot.map(z);
28                         if(z.mod()>MandelbrotMap.CONVERGENT_BOUND)
29                                 return i+1;
30                 }
31                 return 0;
32         }
33         public int isMember(double zRe,double zIm,final int maxIter) {
34                 final double cRe=mbrot.getConstant().real();
35                 final double cIm=mbrot.getConstant().imag();
36                 double tmp;
37                 for(int i=0;i<maxIter;i++) {
38                         tmp=2.0*zRe*zIm+cIm;
39                         zRe=zRe*zRe-zIm*zIm+cRe;
40                         zIm=tmp;
41                         if(zRe*zRe+zIm*zIm>MandelbrotMap.CONVERGENT_BOUND*MandelbrotMap.CONVERGENT_BOUND)
42                                 return i+1;
43                 }
44                 return 0;
45         }
46 }
47
48
Popular Tags