Beispiel #1
0
        public double getModulus()
        {
            double square     = MAL.Power(real, 2) + MAL.Power(imaginary, 2);
            double complement = MAL.SquareRoot(square, InstantiationDecimals);

            return(complement);
        }
Beispiel #2
0
 public Complex(double m, double a, bool w)//Constructive method for modulus argument.
 {
     argument  = MAL.Round(a, InstantiationDecimals);
     modulus   = MAL.Round(m, InstantiationDecimals);
     real      = MAL.Round((m * MAL.Cos(a)), InstantiationDecimals);
     imaginary = MAL.Round((m * MAL.Sin(a)), InstantiationDecimals);
 }
Beispiel #3
0
 public Complex(double r, double i)
 {
     real      = MAL.Round(r, InstantiationDecimals);
     imaginary = MAL.Round(i, InstantiationDecimals);
     modulus   = MAL.Round(getModulus(), InstantiationDecimals);
     argument  = MAL.Round(getArgument(), InstantiationDecimals);
 }
Beispiel #4
0
        private static Complex multiplyAndDivide(Complex x, Complex y, bool division)
        {
            double pi = MAL.Pi();
            double resultantModulus;
            double resultantArgument;

            if (division)
            {
                resultantModulus  = x.modulus / y.modulus;
                resultantArgument = x.argument - y.argument;
            }
            else//This occurs when division is false
            {
                resultantModulus  = x.modulus * y.modulus;
                resultantArgument = x.argument + y.argument;
            }
            if (resultantArgument > pi)
            {
                resultantArgument -= 2 * pi;
            }
            if (resultantArgument < -pi)
            {
                resultantArgument += 2 * pi;
            }
            Complex resultantNumber = new Complex(resultantModulus, resultantArgument, true);

            return(resultantNumber);
        }
Beispiel #5
0
        public string outputRealImaginary()
        {
            string realImag;

            if (imaginary < 0)
            {
                realImag = Convert.ToString(MAL.Round(real, OutputDecimals)) + Convert.ToString(MAL.Round(imaginary, OutputDecimals)) + "i";
            }
            else
            {
                realImag = Convert.ToString(MAL.Round(real, OutputDecimals)) + " + " + Convert.ToString(MAL.Round(imaginary, OutputDecimals)) + "i";
            }
            return(realImag);
        }
Beispiel #6
0
        private void Graph_Load(object sender, EventArgs e)
        {
            Width    = ScreenWidth / CentreOfGraphScale - ScreenHeight / 4;
            Height   = Width;
            Location = new Point(startingX, startingY);
            double[] scalingTest = new double[2];
            double   scalingTrial;

            switch (typeOfGraph)
            {
            case "MIDPOINT":
                scalingTest[0]     = Values.Max();
                scalingTest[1]     = MAL.Modulus(Values.Min());
                scalingTrial       = scalingTest.Max();
                significantFigures = MAL.Exponent(scalingTrial, ScaleBase);
                ScalingFactor      = MAL.Power(ScaleBase, significantFigures);
                break;

            case "HALFLINE":
                scalingTest[0]     = MAL.Modulus(Values[0]);
                scalingTest[1]     = MAL.Modulus(Values[1]);
                scalingTrial       = scalingTest.Max();
                significantFigures = MAL.Exponent(scalingTrial, ScaleBase);
                ScalingFactor      = MAL.Power(ScaleBase, significantFigures);
                break;

            case "CIRCLE":
                scalingTest[0]     = MAL.Modulus(Values[0]);
                scalingTest[1]     = MAL.Modulus(Values[1]);
                scalingTrial       = scalingTest.Max() + Values[2];
                significantFigures = MAL.Exponent(scalingTrial, ScaleBase);
                ScalingFactor      = MAL.Power(ScaleBase, significantFigures);
                break;

            case "DISPLAY":
                scalingTest[0]     = MAL.Modulus(Values[0]);
                scalingTest[1]     = MAL.Modulus(Values[1]);
                scalingTrial       = scalingTest.Max();
                significantFigures = MAL.Exponent(scalingTrial, ScaleBase);
                ScalingFactor      = MAL.Power(ScaleBase, significantFigures);
                break;
            }
        }
Beispiel #7
0
        public double getArgument()
        {
            double Pi = MAL.Pi();

            if (real == 0)
            {
                if (imaginary < 0)
                {
                    return(-Pi / 2);
                }
                else if (imaginary > 0)
                {
                    return(Pi / 2);
                }
                else
                {
                    return(0);
                }
            }
            double x     = MAL.Modulus(imaginary / real);
            double angle = MAL.Arctan(x);

            if (real < 0 && imaginary < 0)
            {
                angle = angle - Pi;
            }
            else if (real < 0)
            {
                angle = Pi - angle;//This is the part that has changed - the geometry is now correct.
            }
            else if (imaginary < 0)
            {
                angle = -angle;
            }
            return(angle);
        }
Beispiel #8
0
        public string outputModulusArgument()
        {
            string modulusArgument = Convert.ToString(MAL.Round(modulus, OutputDecimals)) + "(cos" + Convert.ToString(MAL.Round(argument, OutputDecimals)) + " + isin" + Convert.ToString(MAL.Round(argument, OutputDecimals)) + ")";

            return(modulusArgument);
        }
Beispiel #9
0
        private void Graph_Paint(object sender, PaintEventArgs e)
        {
            double     Unit     = Width / 22;
            Pen        blackPen = new Pen(Brushes.Black, 2);
            Pen        redPen   = new Pen(Brushes.Red, 3);
            Font       font     = new Font("Microsoft Sans Serif", (int)(5 * Unit / 9 - (MAL.Modulus(significantFigures - 1))));
            SolidBrush brush    = new SolidBrush(Color.Black);

            e.Graphics.DrawLine(blackPen, Width / CentreOfGraphScale, 0, Width / CentreOfGraphScale, Height);
            e.Graphics.DrawLine(blackPen, 0, Height / CentreOfGraphScale, Width, Height / CentreOfGraphScale);
            for (int i = 1; i <= 21; i++)
            {
                if (i != 11)
                {
                    e.Graphics.DrawLine(blackPen, (float)(i * Unit + Unit / 10), Height / CentreOfGraphScale - Height / 80, (float)(i * Unit + Unit / 10), Height / CentreOfGraphScale + Height / 80);
                    e.Graphics.DrawLine(blackPen, Width / CentreOfGraphScale - Width / 80, (float)(i * Unit + Unit / 10), Width / CentreOfGraphScale + Width / 80, (float)(i * Unit + Unit / 10));
                }
            }
            int n = 1;

            for (int i = -10; i <= 10; i++)
            {
                PointF ImagAxis;
                PointF RealAxis;
                if (i % 2 == 0)
                {
                    ImagAxis = new PointF(Width / CentreOfGraphScale + Width / 55, (float)(Height - (n * Unit) - Unit / CentreOfGraphScale));
                    RealAxis = new PointF((float)(n * Unit - Unit / 3), Width / CentreOfGraphScale + Width / 125);
                }
                else
                {
                    RealAxis = new PointF((float)outOfRangeValue, (float)outOfRangeValue);
                    ImagAxis = new PointF((float)outOfRangeValue, (float)outOfRangeValue);
                }
                if (i == 0)
                {
                    ImagAxis = new PointF((float)outOfRangeValue, (float)outOfRangeValue);
                }
                string number = Convert.ToString(i * ScalingFactor);
                e.Graphics.DrawString(number, font, brush, RealAxis);
                e.Graphics.DrawString(number, font, brush, ImagAxis);
                n++;
            }
            switch (typeOfGraph)
            {
            case "MIDPOINT":
                Complex Coordinates1 = new Complex(Values[0], Values[2]);
                Complex Coordinates2 = new Complex(Values[1], Values[3]);
                Complex Midpoint     = Complex.calculateMidpoint(Coordinates1, Coordinates2);
                double  Gradient     = Complex.calculatePerpendicularGradient(Coordinates1, Coordinates2);
                //Scale the graph to accept large and small values; also makes the coordinates relative to the centre of the graph.
                //Scaling and drawing coordinates centrally is used later.
                //Below is how the bisector is drawn.
                e.Graphics.DrawLine(redPen, Width / 2 + (float)(Unit * (Midpoint.real / ScalingFactor - 22)), Width / CentreOfGraphScale - (float)(Unit * (Midpoint.imaginary / ScalingFactor - Gradient * 22)), Width / CentreOfGraphScale + (float)(Unit * (Midpoint.real / ScalingFactor + 22)), Width / CentreOfGraphScale - (float)(Unit * (Midpoint.imaginary / ScalingFactor + Gradient * 22)));
                //Draws coordinates of complex numbers as crosses.
                e.Graphics.DrawLine(redPen, Width / CentreOfGraphScale + (float)(Unit * (Coordinates1.real / ScalingFactor - DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Coordinates1.imaginary / ScalingFactor - DrawCrossCoordinates)), Width / CentreOfGraphScale + (float)(Unit * (Coordinates1.real / ScalingFactor + DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Coordinates1.imaginary / ScalingFactor + DrawCrossCoordinates)));
                e.Graphics.DrawLine(redPen, Width / CentreOfGraphScale + (float)(Unit * (Coordinates1.real / ScalingFactor - DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Coordinates1.imaginary / ScalingFactor + DrawCrossCoordinates)), Width / CentreOfGraphScale + (float)(Unit * (Coordinates1.real / ScalingFactor + DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Coordinates1.imaginary / ScalingFactor - DrawCrossCoordinates)));
                e.Graphics.DrawLine(redPen, Width / CentreOfGraphScale + (float)(Unit * (Coordinates2.real / ScalingFactor - DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Coordinates2.imaginary / ScalingFactor - DrawCrossCoordinates)), Width / CentreOfGraphScale + (float)(Unit * (Coordinates2.real / ScalingFactor + DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Coordinates2.imaginary / ScalingFactor + DrawCrossCoordinates)));
                e.Graphics.DrawLine(redPen, Width / CentreOfGraphScale + (float)(Unit * (Coordinates2.real / ScalingFactor - DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Coordinates2.imaginary / ScalingFactor + DrawCrossCoordinates)), Width / CentreOfGraphScale + (float)(Unit * (Coordinates2.real / ScalingFactor + DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Coordinates2.imaginary / ScalingFactor - DrawCrossCoordinates)));
                break;

            case "HALFLINE":
                Complex endCoordinates = new Complex(32, Values[2], true);    //Creates a new complex number with the same argument and a modulus outside the graph.
                //Draws the halfline.
                e.Graphics.DrawLine(redPen, Width / CentreOfGraphScale + (float)(Unit * Values[0] / ScalingFactor), Width / CentreOfGraphScale - (float)(Unit * Values[1] / ScalingFactor), Width / CentreOfGraphScale + (float)(Unit * (endCoordinates.real + Values[0] / ScalingFactor)), Width / CentreOfGraphScale - (float)(Unit * (endCoordinates.imaginary + Values[1] / ScalingFactor)));
                //Draws starting coordinates of complex number as a cross.
                e.Graphics.DrawLine(redPen, Width / CentreOfGraphScale + (float)(Unit * (Values[0] / ScalingFactor - DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Values[1] / ScalingFactor - DrawCrossCoordinates)), Width / CentreOfGraphScale + (float)(Unit * (Values[0] / ScalingFactor + DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Values[1] / ScalingFactor + DrawCrossCoordinates)));
                e.Graphics.DrawLine(redPen, Width / CentreOfGraphScale + (float)(Unit * (Values[0] / ScalingFactor - DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Values[1] / ScalingFactor + DrawCrossCoordinates)), Width / CentreOfGraphScale + (float)(Unit * (Values[0] / ScalingFactor + DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Values[1] / ScalingFactor - DrawCrossCoordinates)));
                break;

            case "CIRCLE":
                try
                {
                    //The radius must be subtracted from a for x and added to b for y as DrawPie uses (x,y) as coordinates of top left corner of the square surrounding the circle.
                    e.Graphics.DrawPie(redPen, Width / CentreOfGraphScale + (float)(Unit * (Values[0] - Values[2]) / ScalingFactor), Width / CentreOfGraphScale - (float)(Unit * (Values[1] + Values[2]) / ScalingFactor), (float)(Unit * Values[2] * 2 / ScalingFactor), (float)(Unit * 2 * Values[2] / ScalingFactor), 360, 360);    //diameter = 2*radius.
                    //Draws centre as a cross
                    e.Graphics.DrawLine(redPen, Width / CentreOfGraphScale + (float)(Unit * (Values[0] / ScalingFactor - DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Values[1] / ScalingFactor - DrawCrossCoordinates)), Width / CentreOfGraphScale + (float)(Unit * (Values[0] / ScalingFactor + DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Values[1] / ScalingFactor + DrawCrossCoordinates)));
                    e.Graphics.DrawLine(redPen, Width / CentreOfGraphScale + (float)(Unit * (Values[0] / ScalingFactor - DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Values[1] / ScalingFactor + DrawCrossCoordinates)), Width / CentreOfGraphScale + (float)(Unit * (Values[0] / ScalingFactor + DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Values[1] / ScalingFactor - DrawCrossCoordinates)));
                }
                catch
                {
                    MessageBox.Show("Error: The circle must have a positive radius");
                }
                break;

            case "DISPLAY":
                e.Graphics.DrawLine(redPen, Width / CentreOfGraphScale, Width / CentreOfGraphScale, Width / CentreOfGraphScale + (float)(Unit * (Values[0] / ScalingFactor)), Width / CentreOfGraphScale - (float)(Unit * (Values[1] / ScalingFactor)));
                e.Graphics.DrawLine(redPen, Width / CentreOfGraphScale + (float)(Unit * (Values[0] / ScalingFactor - DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Values[1] / ScalingFactor - DrawCrossCoordinates)), Width / CentreOfGraphScale + (float)(Unit * (Values[0] / ScalingFactor + DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Values[1] / ScalingFactor + DrawCrossCoordinates)));
                e.Graphics.DrawLine(redPen, Width / CentreOfGraphScale + (float)(Unit * (Values[0] / ScalingFactor - DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Values[1] / ScalingFactor + DrawCrossCoordinates)), Width / CentreOfGraphScale + (float)(Unit * (Values[0] / ScalingFactor + DrawCrossCoordinates)), Width / CentreOfGraphScale - (float)(Unit * (Values[1] / ScalingFactor - DrawCrossCoordinates)));
                break;
            }
        }