コード例 #1
0
 /// <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));
     }
 }
コード例 #2
0
        /// <summary>
        /// Divides this ComplexNum by a given one
        /// </summary>
        /// <param name="n">The ComplexNum to divide with</param>
        public void Divide(ComplexNum n)
        {
            double a = real;
            double b = complex;
            double c = n.GetReal();
            double d = n.GetComplex();

            //Trust me on this one
            real    = (a * c + b * d) / (c * c + d * d);
            complex = (b - a * d) / (c * c + d * d);
        }
コード例 #3
0
        /// <summary>
        /// Finds the product of a ComplexNum and this one
        /// </summary>
        /// <param name="n">The ComplexNum to be multiplied</param>
        public void Multiply(ComplexNum n)
        {
            double a = real;
            double b = complex;
            double c = n.GetReal();
            double d = n.GetComplex();

            //Using FOIL to determine new values
            //(a + bi)(c + di)
            real    = (a * c) - (b * d);
            complex = (a * d) + (b * c);
        }
コード例 #4
0
 /// <summary>
 /// Subtracts a ComplexNum value from this one
 /// </summary>
 /// <param name="n">The ComplexNum to be subtracted</param>
 public void Subtract(ComplexNum n)
 {
     real    -= n.GetReal();
     complex -= n.GetComplex();
 }
コード例 #5
0
 /// <summary>
 /// Adds a ComplexNum value to this one
 /// </summary>
 /// <param name="n">The ComplexNum to be added</param>
 public void Add(ComplexNum n)
 {
     real    += n.GetReal();
     complex += n.GetComplex();
 }