Example #1
0
            public static complexnumber multiply(complexnumber z1, complexnumber z2)
            {
                complexnumber z3 = new complexnumber(0, 0);

                // (a + bi)(c + di) = ac - bd + i(ad + bc);
                z3.real = z1.real * z2.real - z1.imag * z2.imag;
                z3.imag = z1.real * z2.imag + z1.imag * z2.real;
                return(z3);
            }
Example #2
0
 public Form1()
 {
     InitializeComponent();
     textBox3.Visible = cbShowErrors.Checked;
     z1             = new complexnumber(0, 0);
     z3             = new complexnumber(1, 0);
     DoubleBuffered = true;
     fillWhite(pictureBox1);
     drawStuff(true);
     fillColor(pictureBox2, System.Drawing.Color.White);
 }
Example #3
0
        private void drawPoint(PictureBox p, NumericUpDown nud, complexnumber z, System.Drawing.Color c, bool clear)
        {
            int    blob = 2;
            Bitmap b;

            if (clear)
            {
                b = new Bitmap(p.Width, p.Height);
            }
            else
            {
                b = new Bitmap(p.Image);
            }
            Graphics g = Graphics.FromImage(b);

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            Pen   graph   = new Pen(System.Drawing.Color.Black);
            Brush zbrush  = new SolidBrush(c);
            Point zp      = getCoord(z.getReal(), z.getImag(), p, nud);
            Point lefttop = getCoord(0, 1, p, nud);

            Point ninetybottom     = getCoord(Math.PI / 2, -1, p, nud);
            Point oneeightybottom  = getCoord(Math.PI, -1, p, nud);
            Point twoseventybottom = getCoord(3 * Math.PI / 2, -1, p, nud);
            Point rightzero        = getCoord(Math.PI * 2, 0, p, nud);
            Point rightbottom      = getCoord(Math.PI * 2, -1, p, nud);

            Size outersize      = new Size(rightbottom.X - lefttop.X, rightbottom.Y - lefttop.Y);
            Size zerosize       = new Size(rightzero.X - lefttop.X, rightzero.Y - lefttop.Y);
            Size ninetysize     = new Size(ninetybottom.X - lefttop.X, ninetybottom.Y - lefttop.Y);
            Size oneeightysize  = new Size(oneeightybottom.X - lefttop.X, oneeightybottom.Y - lefttop.Y);
            Size twoseventysize = new Size(twoseventybottom.X - lefttop.X, twoseventybottom.Y - lefttop.Y);

            Rectangle outer      = new Rectangle(lefttop, outersize);
            Rectangle zero       = new Rectangle(lefttop, zerosize);
            Rectangle ninety     = new Rectangle(lefttop, ninetysize);
            Rectangle oneeighty  = new Rectangle(lefttop, oneeightysize);
            Rectangle twoseventy = new Rectangle(lefttop, twoseventysize);

            g.DrawRectangle(graph, outer);
            g.DrawRectangle(graph, zero);
            g.DrawRectangle(graph, ninety);
            g.DrawRectangle(graph, oneeighty);
            g.DrawRectangle(graph, twoseventy);


            g.FillEllipse(zbrush, zp.X - blob, zp.Y - blob, blob * 2, blob * 2);
            p.Image = b;
            p.Refresh();
        }
Example #4
0
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                int pbw = pictureBox1.Width;
                int pbh = pictureBox1.Height;

                if (onGraph(e.X, e.Y, pictureBox1))
                {
                    if (e.Button.ToString() == "Left, Right")
                    {
                        z3 = resolvePoint(e.X, e.Y, pictureBox1, maxmodud);
                        if (Math.Abs(z3.getModulus() - Math.Round(z3.getModulus())) < 0.1)
                        {
                            z3 = new complexnumber(Math.Round(z3.getModulus()), 0);
                        }
                        if (cbDrawArcs.Checked)
                        {
                            cbDrawArcs.Checked = false;
                        }
                        else
                        {
                            drawStuff(true);
                        }
                    }
                    else
                    {
                        if (e.Button == MouseButtons.Left)
                        {
                            z1 = resolvePoint(e.X, e.Y, pictureBox1, maxmodud);
                            drawStuff(true);
                        }
                    }
                    return;
                }
                else
                {
                    return;
                }
            }
            catch (Exception eee)
            {
                if (cbShowErrors.Checked)
                {
                    spam("001", eee);
                }
                return;
            }
        }
Example #5
0
        private void btnTheta_Click(object sender, EventArgs e)
        {
            double mytheta;

            if (rbAnglesDegrees.Checked)
            {
                mytheta = (double)thetaUd.Value * (Math.PI / 180);
            }
            else
            {
                mytheta = (double)(thetaUd.Value);
            }
            z1 = new complexnumber(mytheta, 1, true);
            drawStuff(true);
        }
Example #6
0
        public complexnumber resolvePoint(int x, int y, PictureBox p, NumericUpDown nud, int trans)
        {
            complexnumber result = new complexnumber(0, 0);
            double        real   = (x - p.Width / 2) / getDotsPerUnit(p, nud);

            if (Math.Abs(real - (int)(real)) < 0.0001)
            {
                real = (int)(real);
            }
            double imag = ((p.Height / 2 - y) + trans) / getDotsPerUnit(p, nud);

            if (Math.Abs(imag - (int)(imag)) < 0.0001)
            {
                imag = (int)(imag);
            }
            result = new complexnumber(real, imag);
            return(result);
        }