Ejemplo n.º 1
0
        public static Complex Divide(float a, Complex b)
        {
            if (b == 0)
            {
                throw new DivideByZeroException();
            }
            Complex result = new Complex();

            float aa;
            float ad;

            float ba;
            float bd;

            float ra;
            float rd;

            float x;
            float y;

            GreenMath.CartesianToPolar(a, 0, out aa, out ad);
            GreenMath.CartesianToPolar(b.r, b.i, out ba, out bd);

            ra = aa - ba;
            rd = ad / bd;

            GreenMath.PolarToCartesian(ra, rd, out x, out y);

            result.r = (float)x;
            result.i = (float)y;

            return(result);
        }
Ejemplo n.º 2
0
        public float Arg()
        {
            float angle;

            GreenMath.CartesianToPolar(r, i, out angle);

            return(angle);
        }
Ejemplo n.º 3
0
        public static Complex ln(Complex complex)
        {
            Complex result = new Complex();
            float   a;
            float   d;

            GreenMath.CartesianToPolar(complex.r, complex.i, out a, out d);
            result.i = a;
            result.r = (float)Math.Log(d);

            return(result);
        }
Ejemplo n.º 4
0
        public static Complex Normalize(Complex complex)
        {
            Complex result = new Complex();

            float ra;
            float rd;

            GreenMath.CartesianToPolar(complex.r, complex.i, out ra, out rd);
            GreenMath.PolarToCartesian(ra, 1, out result.r, out result.i);

            return(complex);
        }
Ejemplo n.º 5
0
        public static Complex Pow(Complex Base, float Exponent)
        {
            Complex result = new Complex();
            float   ra;
            float   rd;

            float rr;
            float ri;

            GreenMath.CartesianToPolar(Base.r, Base.i, out ra, out rd);
            GreenMath.PolarToCartesian((ra * Exponent), ((float)Math.Pow(rd, Exponent)), out rr, out ri);
            result.r = rr;
            result.i = ri;

            return(result);
        }
Ejemplo n.º 6
0
        public Complex(float real, float imaginary)
        {
            r = real;
            i = imaginary;

            float na;
            float nd;
            float nx;
            float ny;

            GreenMath.CartesianToPolar(r, i, out na, out nd);
            GreenMath.PolarToCartesian(na, 1, out nx, out ny);
            normalized   = new Complex();
            normalized.r = (float)nx;
            normalized.i = (float)ny;
        }
Ejemplo n.º 7
0
        public static List <Complex> Roots(Complex complex, int root)
        {
            List <Complex> results = new List <Complex>();

            for (int j = 1; j <= root; j++)
            {
                float r;
                float i;

                float a;
                float d;

                GreenMath.CartesianToPolar(complex.r, complex.i, out a, out d);
                Console.WriteLine(a + "\t" + d);
                GreenMath.PolarToCartesian((a + (float)Math.PI * 2f * (j - 1) / root), (float)Math.Pow(d, 1f / root), out r, out i);

                results.Add(new Complex(r, i));
            }

            return(results);
        }