public static EscapeTime FindEscapeTimeNoCycleDetection(Complex c, int maxIterations) { if (MandelbulbChecker.IsInsideBulbs(c)) { return(EscapeTime.Infinite); } var zReal = 0.0; var zImag = 0.0; var z2Real = 0.0; var z2Imag = 0.0; for (int i = 0; i < maxIterations; i++) { zImag = 2 * zReal * zImag + c.Imaginary; zReal = z2Real - z2Imag + c.Real; z2Real = zReal * zReal; z2Imag = zImag * zImag; if ((z2Real + z2Imag) > 4) { return(EscapeTime.Discrete(i)); } } return(EscapeTime.Infinite); }
private Tuple <Point, Color> PickColorForPoint(Point point, Area viewPort, Size resolution, bool checkForEdges, IEnumerable <Area> areasToInclude) { var number = viewPort.GetNumberFromPoint(resolution, point); var color = PickColor( () => checkForEdges && areasToInclude.Any(a => a.IsInside(number)), () => MandelbrotFinder.IsInSet(number), () => MandelbulbChecker.IsInsideBulbs(number)); return(Tuple.Create(point, color)); }
public static bool IsInSet(Complex c, BailoutRange bailout) { if (MandelbulbChecker.IsInsideBulbs(c)) { return(true); } double re = 0; double im = 0; // Check for orbits // - Check re/im against an old point // - Only check every power of 2 double oldRe = 0; double oldIm = 0; uint checkNum = 1; // Cache the squares // They are used to find the magnitude; reuse these values when computing the next re/im double re2 = 0; double im2 = 0; for (uint i = 0; i < bailout.Maximum; i++) { var reTemp = re2 - im2 + c.Real; im = 2 * re * im + c.Imaginary; re = reTemp; // Orbit check if (checkNum == i) { if (IsPracticallyTheSame(oldRe, re) && IsPracticallyTheSame(oldIm, im)) { return(true); } oldRe = re; oldIm = im; checkNum = checkNum << 1; } re2 = re * re; im2 = im * im; // Check the magnitude squared against 2^2 if ((re2 + im2) > 4) { return(false); } } return(true); }
/// <summary> /// Determines whether the point is in the set, without using an arbitrary iteration limit. /// </summary> /// <param name="c">The c.</param> /// <remarks> /// Brent's Algorithm is used to detect cycles for points in the set. /// </remarks> /// <returns> /// The <see cref="EscapeTime"/> of the point. /// </returns> public static EscapeTime FindEscapeTime(Complex c) { if (MandelbulbChecker.IsInsideBulbs(c)) { return(EscapeTime.Infinite); } var zReal = 0.0f; var zImag = 0.0f; var z2Real = 0.0f; var z2Imag = 0.0f; var oldZReal = 0.0f; var oldZImag = 0.0f; var cReal = (float)c.Real; var cImag = (float)c.Imaginary; int stepsTaken = 0; int stepLimit = 2; int iterations = 0; while ((z2Real + z2Imag) <= 4) { iterations++; stepsTaken++; zImag = 2 * zReal * zImag + cImag; zReal = z2Real - z2Imag + cReal; z2Real = zReal * zReal; z2Imag = zImag * zImag; if (oldZReal == zReal && oldZImag == zImag) { return(EscapeTime.Infinite); } if (stepsTaken == stepLimit) { oldZReal = zReal; oldZImag = zImag; stepsTaken = 0; stepLimit = stepLimit << 1; } } return(EscapeTime.Discrete(iterations)); }
public static EscapeTime FindEscapeTime(Complex c, int maxIterations) { if (MandelbulbChecker.IsInsideBulbs(c)) { return(EscapeTime.Infinite); } var zReal = 0.0f; var zImag = 0.0f; var z2Real = 0.0f; var z2Imag = 0.0f; var oldZReal = 0.0f; var oldZImag = 0.0f; int stepsTaken = 0; int stepLimit = 2; for (int i = 0; i < maxIterations; i++) { stepsTaken++; zImag = 2 * zReal * zImag + (float)c.Imaginary; zReal = z2Real - z2Imag + (float)c.Real; if (oldZReal == zReal && oldZImag == zImag) { return(EscapeTime.Infinite); } z2Real = zReal * zReal; z2Imag = zImag * zImag; if ((z2Real + z2Imag) > 4) { return(EscapeTime.Discrete(i)); } if (stepsTaken == stepLimit) { oldZReal = zReal; oldZImag = zImag; stepsTaken = 0; stepLimit = stepLimit << 1; } } return(EscapeTime.Infinite); }
public static double FindDistance(Complex c, int maxIterations) { if (MandelbulbChecker.IsInsideBulbs(c)) { return(0); } var z = Complex.Zero; var oldZ = Complex.Zero; var dZ = Complex.Zero; int stepsTaken = 0; int stepLimit = 2; for (int i = 0; i < maxIterations; i++) { stepsTaken++; dZ = 2 * z * dZ + 1; z = z * z + c; if (oldZ == z) { return(0); } if (z.MagnitudeSquared() > 4) { break; } if (stepsTaken == stepLimit) { oldZ = z; stepsTaken = 0; stepLimit = stepLimit << 1; } } var magZ = z.Magnitude; var magDZ = dZ.Magnitude; return(2 * Math.Log(magZ * magZ) * magZ / magDZ); }
protected override bool ValidatePoint(Complex point) { return(!MandelbulbChecker.IsInsideBulbs(point)); }