Exemple #1
0
        public ComplexNumber ComplexFunctionDerivativeValue(ComplexNumber z0In)
        {
            ComplexNumber z = null;

            z = ComplexOperations.Multiply(z0In, 2.0);

            return(z);
        }
Exemple #2
0
        // used in Mandelbrot set fractal
        public ComplexNumber ComplexFunctionValue(ComplexNumber z0In)
        {
            ComplexNumber z = null;

            z = ComplexOperations.Multiply(z0In, z0In);

            return(z);
        }
        public ComputedFractalValues ReturnComputedFractalValues(RectangleInPlane fractalRectangleIn, int xMaxIn, int yMaxIn, IList <FractalColorValue> fractalColorValuesIn, System.Windows.Forms.ProgressBar fractalProgressIn)
        {
            if (fractalColorValuesIn.Count < NumberOfColorUsed)
            {
                throw new FractalObserverException("Fractal PythagorasTree needs more colors that are available in the input parameter fractalColorValuesIn!");
            }

            ComputedFractalValues aComputedFractalValuesValues = new ComputedFractalValues();

            for (int aCurrentYPos = 0; aCurrentYPos < yMaxIn; aCurrentYPos++)
            {
                fractalProgressIn.Value = (int)(100.0 * ((double)aCurrentYPos / (double)yMaxIn));

                for (int aCurrentXPos = 0; aCurrentXPos < xMaxIn; aCurrentXPos++)
                {
                    int tempValue = 0;

                    ComplexNumber c = new ComplexNumber();

                    c.Re = fractalRectangleIn.StartX + Math.Abs(fractalRectangleIn.StartX - fractalRectangleIn.EndX) * ((double)aCurrentXPos / (double)xMaxIn);
                    c.Im = fractalRectangleIn.StartY + Math.Abs(fractalRectangleIn.StartY - fractalRectangleIn.EndY) * ((double)aCurrentYPos / (double)yMaxIn);

                    int n = 0;

                    myZValues[n].Re = 0.0;
                    myZValues[n].Im = 0.0;

                    // computation of value for function z2+c, if it converges (if it is bounded) the point is part of mandelbrot set
                    do
                    {
                        n++;

                        myZValues[n] = ComplexOperations.Add(Equation.ComplexFunctionValue(myZValues[n - 1]), c);
                    } while (((Math.Abs(myZValues[n].Re) < myMaximumValueForConvergation) && (Math.Abs(myZValues[n].Im) < myMaximumValueForConvergation)) && (n < (MaximumNumberOfIterations - 1)));

                    tempValue = n;

                    ComputedFractalValue aCFValue = new ComputedFractalValue();

                    FractalColorValue aFractalColorValue = ReturnColor(tempValue, fractalColorValuesIn);
                    aCFValue.ColorValue = aFractalColorValue;
                    aCFValue.AddComputedPoint(new System.Drawing.Point(aCurrentXPos, aCurrentYPos));
                    aCFValue.TypeOfShape = TypesOfShape.Point;
                    aCFValue.UsedTypeOfCoordinateSystem = TypesOfCoordinateSystem.Screen;

                    aComputedFractalValuesValues.AddComputedFractalValue(aCFValue);
                }
            }

            return(aComputedFractalValuesValues);
        }
Exemple #4
0
        public ComplexNumber ComplexFunctionValue(ComplexNumber z0In)
        {
            ComplexNumber z = null;

            z = ComplexOperations.Multiply(z0In, z0In);
            z = ComplexOperations.Multiply(z, z0In);

            ComplexNumber tempZ = ComplexOperations.Multiply(z0In, 2.0);

            z = ComplexOperations.Substract(z, tempZ);

            z.Re += 2.0;

            return(z);
        }
        public ComputedFractalValues ReturnComputedFractalValues(RectangleInPlane fractalRectangleIn, int xMaxIn, int yMaxIn, IList <FractalColorValue> fractalColorValuesIn, System.Windows.Forms.ProgressBar fractalProgressIn)
        {
            if (fractalColorValuesIn.Count < NumberOfColorUsed)
            {
                throw new FractalObserverException("Fractal PythagorasTree needs more colors that are available in the input parameter fractalColorValuesIn!");
            }

            ComputedFractalValues aComputedFractalValues = new ComputedFractalValues();

            myZRoots.Clear();

            for (int aCurrentYPos = 0; aCurrentYPos < yMaxIn; aCurrentYPos++)
            {
                fractalProgressIn.Value = (int)(100.0 * ((double)aCurrentYPos / (double)yMaxIn));

                for (int aCurrentXPos = 0; aCurrentXPos < xMaxIn; aCurrentXPos++)
                {
                    int tempRoot  = 0;
                    int tempValue = 0;

                    int n = 0;

                    // initial values
                    myZValues[n].Re = fractalRectangleIn.StartX + Math.Abs(fractalRectangleIn.StartX - fractalRectangleIn.EndX) * ((double)aCurrentXPos / (double)xMaxIn);
                    myZValues[n].Im = fractalRectangleIn.StartY + Math.Abs(fractalRectangleIn.StartY - fractalRectangleIn.EndY) * ((double)aCurrentYPos / (double)yMaxIn);

                    // computation of next values until the maximum iteration count or until the conditions are met
                    do
                    {
                        n++;
                        myZValues[n] = ComplexOperations.Substract(myZValues[n - 1], ComplexOperations.Divide(Equation.ComplexFunctionValue(myZValues[n - 1]), Equation.ComplexFunctionDerivativeValue(myZValues[n - 1])));
                    } while (((Math.Abs(myZValues[n].Re - myZValues[n - 1].Re) > myTreshold) || (Math.Abs(myZValues[n].Im - myZValues[n - 1].Im) > myTreshold)) && (n < (MaximumNumberOfIterations - 1)));

                    ComputedFractalValue aCFValue = null;
                    FractalColorValue    aFractalColorValue;

                    // if the solution did not converge to root, then return zero values
                    if (n >= (MaximumNumberOfIterations - 1) || double.IsNaN(myZValues[n].Re) || double.IsNaN(myZValues[n].Im))
                    {
                        aCFValue = new ComputedFractalValue();

                        aFractalColorValue  = ReturnColor(tempRoot, tempValue, fractalColorValuesIn);
                        aCFValue.ColorValue = aFractalColorValue;
                        aCFValue.AddComputedPoint(new System.Drawing.Point(aCurrentXPos, aCurrentYPos));
                        aCFValue.TypeOfShape = TypesOfShape.Point;
                        aCFValue.UsedTypeOfCoordinateSystem = TypesOfCoordinateSystem.Screen;

                        aComputedFractalValues.AddComputedFractalValue(aCFValue);

                        continue;
                    }

                    bool aNewRoot    = true;
                    int  aRootNumber = 0;

                    // find out if the root is new until now, or if the current root was found already
                    for (int i = 0; i < myZRoots.Count; i++)
                    {
                        if ((Math.Abs(myZRoots[i].Re - myZValues[n].Re) < myTreshold) && (Math.Abs(myZRoots[i].Im - myZValues[n].Im) < myTreshold))
                        {
                            aNewRoot    = false;
                            aRootNumber = i;
                            break;
                        }
                    }

                    // if this root is new until now, add new item to myZRoots List
                    if (aNewRoot)
                    {
                        ComplexNumber aComplexRoot = new ComplexNumber();
                        aComplexRoot.Re = myZValues[n].Re;
                        aComplexRoot.Im = myZValues[n].Im;

                        myZRoots.Add(aComplexRoot);

                        aRootNumber = myZRoots.Count - 1;
                    }

                    // sets the computed values for this pixel to return structure and return it
                    tempValue = n;

                    if (aRootNumber == 0)
                    {
                        tempRoot = 1;
                    }
                    else if (aRootNumber == 1)
                    {
                        tempRoot = 2;
                    }
                    else if (aRootNumber == 2)
                    {
                        tempRoot = 3;
                    }
                    else
                    {
                        throw new FractalObserverException("Error occured during computation of fractal, wrong number of roots was found!");
                    }

                    // storing of output of computation
                    aCFValue = new ComputedFractalValue();

                    aFractalColorValue  = ReturnColor(tempRoot, tempValue, fractalColorValuesIn);
                    aCFValue.ColorValue = aFractalColorValue;
                    aCFValue.AddComputedPoint(new System.Drawing.Point(aCurrentXPos, aCurrentYPos));
                    aCFValue.TypeOfShape = TypesOfShape.Point;
                    aCFValue.UsedTypeOfCoordinateSystem = TypesOfCoordinateSystem.Screen;

                    aComputedFractalValues.AddComputedFractalValue(aCFValue);
                }
            }

            return(aComputedFractalValues);
        }