/// <summary> /// Recursive check if a complex number is within the Mandelbrot set /// </summary> /// <param name="z"></param> /// <param name="c"></param> /// <param name="recursions"></param> /// <param name="maxRecursions"></param> /// <returns>TRUE if "c" is within Mandelbrot Set, FALSE otherwise</returns> private bool RecursiveCheck(ComplexNum z, ComplexNum c, int recursions, int maxRecursions) { if (Math.Sqrt(z.GetReal() * z.GetReal() + z.GetComplex() * z.GetComplex()) > MAX_DIST) { //Number blew up return(false); } else if (recursions > maxRecursions) { //Number probably does not blow up return(true); } else { //Run it again z.Squared(); z.Add(c); return(RecursiveCheck(z, c, recursions + 1, maxRecursions)); } }
/// <summary> /// Iterative check if a complex number is within the Mandelbrot set /// </summary> /// <param name="z"></param> /// <param name="c"></param> /// <param name="maxIterations"></param> /// <returns>TRUE if "c" is within Mandelbrot Set, FALSE otherwise</returns> private int IterativeCheck(ComplexNum z, ComplexNum c, int maxIterations) { int iterations = 0; while (true) { if (z.Magnitude() > MAX_DIST) { //Number blew up return(iterations); } else if (iterations >= maxIterations) { //Number probably does not blow up return(maxIterations); } //Run it through the function again z.Multiply(z); z.Add(c); iterations++; } }