Fractal Mathematics

Started by
14 comments, last by Xgkkp 22 years, 2 months ago
I really want to find out about fractal mathematics, does anyone know what the best resources would be? on or offline (books etc).
Advertisement
here, this oughta keep you busy learning for a while

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
MojoWorlds is a fantastic fractal terrain generator. The product is not free, but if you can afford $200 its a great tool for experimenting with programmable fractals (and in the process generating unbelievable renderings of fractal planets).

www.pandromeda.com

Also check out the 300 pages of Doc Musgrave''s PhD dissertation. He''s one of the head guys over at Pandromeda. He worked with Mandelbrot!

http://www.wizardnet.com/musgrave/dissertation.html

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
quote:Original post by krez
here, this oughta keep you busy learning for a while


Good idea to use a search engine. BUT Xgkkp asked for our advice on the "best resources." Google can't necessarily tell him that "these here are the best sites." Please read the post more carefully before sending a hasty and impatient reply, .

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Edited by - grhodes_at_work on February 14, 2002 2:30:28 PM
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
OK, I made a fractal program not so long ago, this I''ll try and explain how to make a simple mandelbrot fractal, if that can be of any help

Im assuming you have some basic knowledge of complex numbers. I defined a class "Complex" that I use here, if you have any questions about that, just ask.

The fractal lies in the so-called complex plane (similar to the x, y plane) And each point is a recusion equation (if thats a new expression, dont worry, ill explain)

In the code I go through each point and check if the recursion equation converge or diverge (more difficult terms hehe; to converge means that it goes towards a spesific value, to diverge means that it goes towards infinity)

  // the complex numbers used in the recursion equationComplex Zone[2];Complex P; // P is the point in the plane// Saving the values as a colorColor result[256][256];// Then define the area in the complex plane that should be rendered// The mandelbrot looks great in the interval:double start_x = -2.0;double end_x = 2.0;double start_y = -2.0;double end_y = 2.0;P.a = start_x; // the real part of P denoted as aP.b = start_y; // the imaginary part of P denoted as b// assigning the distance between each point (end - start = 4)double add = (4.0 / 256.0);// Starting a loop that goes through each of the 256*256 pointsfor(int x = 0; x < 256; x++){  for(int y = 0; y < 256;  y++)  {    //ok, a recursion equation is just basically a row of numbers    //where each of the numbers are a product or sum of some of    //the previous numbers and/or constants    //The mandelbrot fractal are generated out of a recursion    //equation where Z[n] = (Z[n-1])^2 + P, basically what this    //sayss is that each number is equal to the previous one in    //the row to the power of two plus P (P is the point in the    //plane)    //Since we dont have an infinite row of Z''s to use we just    //recycle the ones we declared earlier    //The key point of this is to check if therecursion    //converge or diverge, to do this we check up to Z[499],    //and if its absolute value is not greater than 2 then we    //can safely assume that it converges    Z[1].a = 0;    Z[1].b = 0;    bool converge = true;    for(int c = 0; (c < 500)&&(converge); c++)    {      Z[0] = Z[1]*Z[1] + P;            if(Z[0].abs() > 2.0) // .abs() returns the absolute value      {        converge = false;      }      // recycling      Z[1] = Z[0];    }    if(converge)    {      //if it converge you might want to multiply the color      //value to fit a special color format, as it is often < 1.0      result[x][y].blue = Z[0].abs();      result[x][y].red = 0.0;      result[x][y].green = 0.0;     }    else    {      //if it deverges you usually get very high values (even      //though it exits the loop the first timemits higher than 2      //so i usually divide it by a constant (100 in this case)      result[x][y].blue = 0.0;      result[x][y].red = Z[0].abs(); * 0.01;      result[x][y].green = Z[0].abs(); * 0.01;    }       // now changing P so its ready for the next screen coordinate:    P.a += add;  }  P.b += add;  P.a = start_x;}// the next thing to do is to draw/save the color values in the// "result" array  


Ok I just wrote that out of my head so I might have some dumb mistakes in it, let me know if there is something.

Oh.. and note that you dont have to save the values as color values, you can also make a height map (like I did here)

My post up, your post down, my site here
quote:Original post by Jesper T
Oh.. and note that you dont have to save the values as color values, you can also make a height map (like I did here)


Cool stuff that!



Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
yeah, Google seemed only to give results of links to programs that show fractals, or school sites.

Thanks for the code. Ill go through it tomorrow ( its 00:15 ) and try to understand it, but looking at it briefly, where you have used "Z", did you mean "Zone" because I cannot see where it is declared. also, could you explain the complex data type?
"Z" is the standard variable name that represents complex numbers in textbooks. Jesper T probably meant to use either Zone or "Z" everywhere. Perhaps he choose Z because it is commonly used.

The complex data type is just a complex (aka "imaginary") number. It has a real and imaginary part. Very confusing terminology. Really, its like a vector. The "x" component is defined to be the "real" component, and the "y" component is defined to be the "imaginary" component. In the mathematics of complex numbers, the imaginary component sort of represents a frequency, as in either a time frequency (e.g, frequency of a sound vibration) or a space frequency (e.g., the frequency of the wave of a water ripple). The real component represents a parameter that varies with rate (rate of acceleration or deceleration for example, or the rate at which the water ripple settles to zero leaving only still water).

I know that''s confusing. Its just definitions. Complex math and the complex variable type are just tools for solving a set of equations. Look at the reference material on fractals (especially mandelbrot set) and think of complex numbers in terms of what they present.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Yes, what grhodes said.

And I can add some calculation rules:

'i' is usually used to denote the imaginary number, where:

i*i = -1

thus:

sqrt(-1) = i and -i
(-i, since (-i)^2 = (-1*i)^2 = (-1)^2 * (i)^2 = 1 * -1 = -1)

and:

(3i)*(3i) = (3*3)*(i*i) = 9 * -1 = -9

thus:

sqrt(-9) = sqrt(-1*9) = sqrt(-1)*sqrt(9) = 3i and -3i

As grhodes said the complex number consist of a imaginary part and a real part:

Z = a + b*i, or on 'x,y coordinate' form: Z=(a, b)

(here a is a real number, and b is its frequency (since its multiplyed with i)

To add two complex numbers:

Z = a+b*i, P = c+d*i, into the complex result X = x + y*i

Z + P = (a+ b*i)+(c + d*i) = a+c + (b+d)*i =>

x = a+c, and y = b+d

To multiply two complex numbers:

Z = a+b*i, P = c+d*i, into the complex result X = x + y*i

Z * P = (a+ b*i)+(c + d*i) = a*c + a*d*i + b*i*c + b*i*d*i = a*c + b*d*i*i + (a*d + b*c)*i = a*c - b*d + (a*d + b*c)*i =>

x = a*c - b*d
y = a*d + b*c

Thats basically all you need for the mandelbrot fractal.

Here is how I defined the Complex data type:

    class Complex {public:	Complex( double ar = 0.0, double bi = 0.0 );	double absl( void );	double argu( void );	Complex conjugate( void );	Complex inverse( void );	Complex root( void );	Complex operator+( Complex &right );	Complex operator-( Complex &right );	Complex operator*( Complex &right );	Complex operator/( Complex &right );	Complex operator+( double  right );	Complex operator-( double  right );	Complex operator*( double  right );	Complex operator/( double  right );	void operator+=( Complex &right );	void operator-=( Complex &right );	void operator*=( Complex &right );	void operator/=( Complex &right );	void operator+=( double  right );	void operator-=( double  right );	void operator*=( double  right );	void operator/=( double  right );	double a;	double b;	~Complex( void );};Complex::Complex( double ar, double bi){	a = ar;	b = bi;}double Complex::absl( void ){	return sqrt((a*a)+(b*b));}double Complex::argu( void ){	return asin(b/sqrt((a*a)+(b*b)));}Complex Complex::conjugate( void ){	Complex ret(a, -b);	return ret;}Complex Complex::inverse( void ){	double abt = (a*a)+(b*b);	if(abt > 0)	{		abt = 1.0 / abt;	}	Complex ret(a*abt,-b*abt);	return ret;}Complex Complex::root( void ){	Complex ret;	double arg = argu();	double rad = absl();	ret.a = sqrt(rad)*cos((2.0*PI + arg)/2.0);	ret.b = sqrt(rad)*sin((2.0*PI + arg)/2.0);	return ret;}Complex Complex::operator +( Complex &right ){	Complex ret( a + right.a, b + right.b );	return ret;}Complex Complex::operator -( Complex &right ){	Complex ret( a - right.a, b - right.b );	return ret;}Complex Complex::operator *( Complex &right ){	Complex ret( ((a*right.a)-(b*right.b)), ((a*right.b)+(b*right.a)) );	return ret;}Complex Complex::operator /( Complex &right ){	Complex ret;	ret.a = ((a*right.a)+(b*right.b))/((right.a*right.a)+(right.b*right.b));	ret.b = ((b*right.a)+(a*right.b))/((right.a*right.a)+(right.b*right.b));	return ret;}Complex Complex::operator +( double right ){	Complex ret((a+right), b);	return ret;}Complex Complex::operator -( double right ){	Complex ret((a-right), b);	return ret;}Complex Complex::operator *( double right ){	Complex ret((a*right), (b*right));	return ret;}Complex Complex::operator /( double right ){	Complex ret((a/right), (b/right));	return ret;}void Complex::operator +=( Complex &right ){	a += right.a;	b += right.b;}void Complex::operator -=( Complex &right ){	a -= right.a;	b -= right.b;}void Complex::operator *=( Complex &right ){	a = ((a*right.a)-(b*right.b));	b = ((a*right.b)+(b*right.a));}void Complex::operator /=( Complex &right ){	a = ((a*right.a)+(b*right.b))/((right.a*right.a)+(right.b*right.b));	b = ((b*right.a)+(a*right.b))/((right.a*right.a)+(right.b*right.b));}void Complex::operator +=( double right ){	a += right;}void Complex::operator -=( double right ){	a -= right;}void Complex::operator *=( double right ){	a *= right;	b *= right;}void Complex::operator /=( double right ){	a /= right;	b /= right;}Complex::~Complex( void ) { }    


Note that I have made the square root function only return one value to make it simpler even though that is not entirewly correct (it should return 2 values)
(edit) I think that there exists one standard c++ complex data type too (which probably is a lot faster than mine)

My post up, your post down, my site here

Edited by - Jesper T on February 15, 2002 1:39:07 AM
whenever i leave this line in
          Color result[256][256];  it gives an "Unhandled Exception: Stack overflow"i have defined Color as      struct Color{	double red;	double green;	double blue;};    

if comment out that line and the references to it, it works fine ( i assume, i can see no output).

Thanks alot so far anyway though.

Edit: If i move the declaration of result outside of the function, it works, does anyone know why? Also, I now have a nice looking mandelbrot fractal. Presumably it can be removed to give results like the nice pics you see on the internet.
also, i put the range down to a very small value (i have modified add to accept different x any y values) and it isn't drawing much. how can i get it to calculate in higer detail in smaller intervals, like the demos you see that can zoom down n branches.

Edited by - Xgkkp on February 15, 2002 2:15:59 PM

This topic is closed to new replies.

Advertisement