Results 1 to 7 of 7
Thread: Mandelbrot set!
 05112012, 05:58 AM #1
 Join Date
 Jan 2011
 Location
 Richmond, Virginia
 Posts
 3,069
 Blog Entries
 3
 Rep Power
 10
Mandelbrot set!
Hey guys,
I haven't been doing any interesting projects lately (besides class projects, which aren't very interesting). So, as an exercise I decided to tackle mandelbrot sets. It's actually been quite simple and the majority of my code was representing Complex numbers. My program is the inefficiency I am running into.
I am wondering how to make a quicker method to test for convergence. Here is what I've got:
Java Code:private boolean converges(ComplexNum input){ int count = 0; ComplexNum start = input; ComplexNum zCurrent = new ComplexNum(); ComplexNum zNext = new ComplexNum(); while(zCurrent.getReal() < 2 && zCurrent.getImaginary() < 2 && count < 45){ zNext = zCurrent.mult(zCurrent); zNext = zNext.add(input); zCurrent = zNext; ++count; } if(zCurrent.getReal() < 2 && zCurrent.getImaginary() < 2){ return true; } return false; }
Java Code:public void generateSet(){ for(double i = 2; i < 2; i += .001){ for(double j = 2; j < 2; j+= .001){ ComplexNum current = new ComplexNum(i, j); if(converges(current)){ set.add(current); } } } }
Picture for anyone interested:
Thanks in advance.Last edited by sunde887; 05112012 at 06:06 AM.
 05112012, 08:03 AM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,247
 Blog Entries
 7
 Rep Power
 24
Re: Mandelbrot set!
There's a horizontal axis of symmetry (i.e. if (x,y) is an element of your set so is (x,y)); this speeds up the entire thing by a factor of 2.
kind regards,
JoThe only person who got everything done by Friday was Robinson Crusoe.

Re: Mandelbrot set!
I don't know about speeding up the algorithms, but I do know that the images of this and the corresponding Julia sets get a whole lot more interesting when you assign different colors for different speeds of divergence (not sure if that is the right word), as my forum image demonstrates.
 05112012, 09:16 PM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,247
 Blog Entries
 7
 Rep Power
 24
Re: Mandelbrot set!
The only person who got everything done by Friday was Robinson Crusoe.
 05112012, 09:49 PM #5
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,247
 Blog Entries
 7
 Rep Power
 24
Re: Mandelbrot set!
b.t.w. your stop condition in the while loop isn't correct; it should be c < 2, i.e. for c == a+b*i, a*a+b*b < 4
kind regards,
JosThe only person who got everything done by Friday was Robinson Crusoe.
 05122012, 03:01 AM #6
 Join Date
 Jan 2011
 Location
 Richmond, Virginia
 Posts
 3,069
 Blog Entries
 3
 Rep Power
 10
Re: Mandelbrot set!
 05122012, 10:12 AM #7
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,247
 Blog Entries
 7
 Rep Power
 24
Re: Mandelbrot set!
Have a look here.
kind regards,
JosThe only person who got everything done by Friday was Robinson Crusoe.
Similar Threads

HELP! Mandelbrot Set Explorer, many GUI runtime exceptions, need HELP plz!
By jamcswain in forum Advanced JavaReplies: 23Last Post: 03232012, 06:05 PM 
In honor of Benoît Mandelbrot. May he rest in peace.
By Fubarable in forum Forum LobbyReplies: 0Last Post: 10172010, 09:31 PM 
How to draw Mandelbrot in Java
By Java Tip in forum java.awtReplies: 0Last Post: 06232008, 11:21 PM
Bookmarks