Results 1 to 7 of 7
Thread: Mandelbrot set!
- 05-11-2012, 05:58 AM #1
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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:
To actually construct the set, I've used this simple piece of codeJava 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; }
Once the set is generated I simply draw an oval for each item in the set.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; 05-11-2012 at 06:06 AM.
- 05-11-2012, 08:03 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
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,
JoWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
-
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.
- 05-11-2012, 09:16 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: Mandelbrot set!
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-11-2012, 09:49 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-12-2012, 03:01 AM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Mandelbrot set!
- 05-12-2012, 10:12 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: Mandelbrot set!
Have a look here.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
HELP! Mandelbrot Set Explorer, many GUI runtime exceptions, need HELP plz!
By jamcswain in forum Advanced JavaReplies: 23Last Post: 03-23-2012, 05:05 PM -
In honor of Benoît Mandelbrot. May he rest in peace.
By Fubarable in forum Forum LobbyReplies: 0Last Post: 10-17-2010, 09:31 PM -
How to draw Mandelbrot in Java
By Java Tip in forum java.awtReplies: 0Last Post: 06-23-2008, 11:21 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks