Article View: sci.fractals
Article #156Re: Mandelbrot Set
From: Daniel Green
Date: Wed, 14 Oct 1992 19:57
Date: Wed, 14 Oct 1992 19:57
76 lines
2882 bytes
2882 bytes
In article 24563@sol.UVic.CA, aschoorl@engr.UVic.CA (Andre Schoorl) writes:
>
> Can anybody simply tell me what the equation of the Mandelbrot set is?
> Ever book I've ever seen expects you to know it before cracking the cover.
>
I'm sure most readers will know this stuff in their sleep, but I remember
going through the same head-scratching just to get started, so I've included
mandel.c which contains the relevant info embedded in simple, working C code.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* * * * * * * * * *\
* MANDEL.C *
* by Daniel Green *
\* * * * * * * * * */
#define BIG 100.0
#define NORMSQRD(zx,zy) (zx*zx+zy*zy)
/* complex addition */
#define PLUS(resultx,resulty, ax,ay, bx,by) \
(resultx = ax + bx, \
resulty = ay + by)
/* complex multiplication */
#define TIMES(resultx,resulty, ax,ay, bx,by) \
(resultx = ax*bx - ay*by, \
resulty = ay*bx + ax*by)
/* set to most natural floating point type */
typedef double Real;
/*
* Iterates the Mandelbrot function Z = Z^2 + C where C is a point in
* the complex plane, and Z is initially complex zero. Iteration ends when
* the magnitude of Z grows too large, or if the given maximum number
* of iterations is reached (given point is then assumed to be in the set).
*
* Returns 0 if in the set, otherwise number of iterations to divergence.
* Note: zx and zy are initialized to x and y, and the counter is initialized
* to 1 because that is what they would always be after the first iteration
* if they were all initialized to zero as they officially should be.
*/
int mandel(x, y, max_iterations)
Real x, y;
int max_iterations;
{
register Real zx, zy, cx, cy, tempx, tempy;
register int iterations;
zx = cx = x;
zy = cy = y;
for (iterations = 1;
(NORMSQRD(zx,zy) < BIG) && (iterations < max_iterations);
iterations++) {
TIMES(tempx,tempy, zx,zy, zx,zy);
PLUS(zx,zy, tempx,tempy, cx,cy);
}
return iterations == max_iterations ? 0 : iterations;
}
---
Daniel Green
danielg@autodesk.com
___________ ___________
| | | |
| _________ | _________
| | | | | |
| | _______ | | _______
| | | | | | | |
---| | _____ --| | _____
---| | D | --| | D |
---| G| --| G|
----- -----
Technical Details
Message-ID:
<17780@autodesk.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!autodesk!m31!danielgReferences:
<1992Oct13.151335.24563@sol.UVic.CA>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!autodesk!m31!danielg From: danielg@autodesk.com (Daniel Green) Newsgroups: sci.fractals Subject: Re: Mandelbrot Set Message-ID: <17780@autodesk.COM> Date: 14 Oct 92 19:57:31 GMT References: <1992Oct13.151335.24563@sol.UVic.CA> Sender: news@Autodesk.COM Reply-To: danielg@autodesk.com Organization: Autodesk, Inc. Lines: 77