Ejemplo n.º 1
0
        private void Form1_MouseWheel(object sender, MouseEventArgs e)
        {
            if (toolStripButton2.Checked)
            {
                if (e.Delta > 0)
                {
                    zoom.ZoomIn();
                }
                else
                {
                    zoom.ZoomOut();
                }
            }
            else
            {
                E += 1 * Math.Sign(e.Delta);

                foreach (PointF[] segment in MathGraphic.Tabulate(QDotPlus, x1, x2, h))
                {
                    listik.Add(segment);
                }

                mgQDotPlus.GraphicLayersPoints = listik.ToArray();
            }
            Refresh();
        }
Ejemplo n.º 2
0
Archivo: Form1.cs Proyecto: a-27m/vssdb
        private void AddGraphic(double _x0, double _v0)
        {
            float       T = 4f;
            float       n = 4;
            MathGraphic m;

            Complex X0 = new Complex(_x0);
            Complex V0 = new Complex(_v0);

            A1 = (V0 - k2 * X0) / (k1 - k2);
            A2 = (V0 - k1 * X0) / (k2 - k1);

            m = new MathGraphic(Color.Green, DrawModes.DrawLines,
                                fx, fv, -T, T, 1e-2f);
            grs.Add(m);

            PointF[] ar;
            float    dt = 15f / zoom;

            for (int i = 0; i <= n; i++)
            {
                ar = new PointF[3];

                double t = i * 2f * T / n - 2f * T;

                float x1 = (float)fx(t);
                float y1 = (float)fv(t);

                float x2 = (float)fx(t + dt);
                float y2 = (float)fv(t + dt);

                float xs = x2 - x1;
                float ys = y2 - y1;

                float ds = (float)Math.Sqrt(xs * xs + ys * ys);

                //xs *= dt / ds;
                //ys *= dt / ds;
                xs = xs / ds * dt;
                ys = ys / ds * dt;

                float xn = ys / 3f;
                float yn = -xs / 3f;

                ar[0] = new PointF(x1 + xn, y1 + yn);
                ar[1] = new PointF(x1 + xs, y1 + ys);
                ar[2] = new PointF(x1 - xn, y1 - yn);

                m             = new MathGraphic(ar);
                m.DrawingMode = DrawModes.DrawLines;
                m.PenColor    = Color.Green;
                m.PenWidth    = 0f;

                grs.Add(m);
            }
        }
Ejemplo n.º 3
0
        private void buttonGO_Click(object sender, EventArgs e)
        {
            MathGraphic m;

            try
            {
                x0   = double.Parse(textBoxX0.Text);
                v0   = double.Parse(textBoxV0.Text);
                k    = double.Parse(textBoxK.Text);
                w    = double.Parse(textBoxW.Text);
                n    = double.Parse(textBoxN.Text);
                P    = double.Parse(textBoxP.Text);
                T0   = float.Parse(textBoxT0.Text);
                Tmax = float.Parse(textBoxT1.Text);
            }
            catch (FormatException) {
                MessageBox.Show("Wrong number format");

                textBoxX0.Text = x0.ToString();
                textBoxV0.Text = v0.ToString();
                textBoxK.Text  = k.ToString();
                textBoxW.Text  = w.ToString();
                textBoxN.Text  = n.ToString();
                textBoxP.Text  = P.ToString();
                textBoxT0.Text = T0.ToString();
                textBoxT1.Text = Tmax.ToString();

                return;
            }

            Compute();
            if (radioXT.Checked)
            {
                grsXt.Clear();

                m = new MathGraphic(Color.Green, DrawModes.DrawLines,
                                    fx, T0, Tmax, 1e-2f);
                grsXt.Add(m);
            }
            if (radioVT.Checked)
            {
                grsVt.Clear();

                m = new MathGraphic(Color.Green, DrawModes.DrawLines,
                                    fv, T0, Tmax, 1e-2f);
                grsVt.Add(m);
            }
            if (radioVX.Checked)
            {
                AddGraphicVX();
            }

            pictureBox1.Refresh();
        }
Ejemplo n.º 4
0
        private void AddGraphicVX()
        {
            MathGraphic m;

            grsVx.Clear();

            m = new MathGraphic(Color.Green, DrawModes.DrawLines,
                                fx, fv, T0, Tmax, 1e-2f);

            grsVx.Add(m);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// adds graph of parametrically defined 2D function
        /// </summary>
        /// <param name="f">Real function of DoubleFunction</param>
        /// <param name="drawMode">Whether to join nodes with lines</param>
        /// <returns>Zero-based index (ID) of newly added graphic</returns>
        public int AddGraphic(DoubleFunction fx, DoubleFunction fy, float t1, float t2,
                              DrawModes drawMode, Color penColor)
        {
            if (grs == null)
            {
                grs = new List <MathGraphic>(100);
            }
            MathGraphic newGraphic = new MathGraphic(penColor, drawMode,
                                                     fx, fy, t1, t2, 0.01f);

            grs.Add(newGraphic);

            return(grs.Count - 1);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// </summary>
        /// <param name="penWidth">Is zooming with graphics of not zero :(</param>
        public int AddPolygon(Color penColor, float penWidth,
                              DrawModes drawMode, params PointF[] pts)
        {
            if (grs == null)
            {
                grs = new List <MathGraphic>(100);
            }

            MathGraphic newGraphic = new MathGraphic(pts);

            newGraphic.DrawingMode = drawMode;
            newGraphic.PenColor    = penColor;
            newGraphic.PenWidth    = penWidth;

            grs.Add(newGraphic);

            return(grs.Count - 1);
        }
Ejemplo n.º 7
0
        //private double QDotMinus(double q)
        //{
        //    return -QDotPlus(q);
        //}

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            mgP = new MathGraphic(
                Color.SlateBlue,
                DrawModes.DrawLines,
                P, x1, x2, h);
            mgP.CurrentColorSchema = MathGraphic.ColorSchema.BlackAndWhite;

            mgQDotPlus = new MathGraphic(
                Color.SlateGray,
                DrawModes.DrawLines,
                QDotPlus, x1, x2, h);
            mgQDotPlus.CurrentColorSchema = MathGraphic.ColorSchema.BlackAndWhite;

            //mgQDotMinus = new MathGraphic(
            //    Color.SlateGray,
            //     DrawModes.DrawLines,
            //     QDotMinus, x1, x2, h);
            //mgQDotMinus.CurrentColorSchema = MathGraphic.ColorSchema.BlackAndWhite;

            Refresh();
        }
Ejemplo n.º 8
0
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ox  += e.X - mx;
                oy1 += e.Y - my;

                Refresh();
            }
            if (e.Button == MouseButtons.Right)
            {
                E = -(e.Y - oy1) / zoom.Y;

                foreach (PointF[] segment in MathGraphic.Tabulate(QDotPlus, x1, x2, h))
                {
                    listik.Add(segment);
                }

                mgQDotPlus.GraphicLayersPoints = listik.ToArray();

                Refresh();
            }
        }
Ejemplo n.º 9
0
Archivo: Form1.cs Proyecto: a-27m/vssdb
        private void buttonGO_Click(object sender, EventArgs e)
        {
            MathGraphic m;

            #region in/out
            try
            {
                h     = double.Parse(textBoxH.Text);
                b11   = double.Parse(textBoxB11.Text);
                b12   = double.Parse(textBoxB12.Text);
                b21   = double.Parse(textBoxB21.Text);
                b22   = double.Parse(textBoxB22.Text);
                C2    = double.Parse(textBoxC2.Text);
                Y0[0] = double.Parse(textBoxN1_0.Text);
                Y0[1] = double.Parse(textBoxN2_0.Text);
                T0    = double.Parse(textBoxT1.Text);
                Tmax  = double.Parse(textBoxT2.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Wrong number format");

                textBoxH.Text    = h.ToString();
                textBoxB11.Text  = b11.ToString();
                textBoxB12.Text  = b12.ToString();
                textBoxB21.Text  = b21.ToString();
                textBoxN1_0.Text = Y0[0].ToString();
                textBoxN2_0.Text = Y0[1].ToString();
                textBoxB22.Text  = b22.ToString();
                textBoxC2.Text   = C2.ToString();
                textBoxT1.Text   = T0.ToString();
                textBoxT2.Text   = Tmax.ToString();

                return;
            }
            #endregion

            Compute();

            if (radioN1T.Checked)
            {
                grsN1T.Clear();

                m = new MathGraphic(Color.Green, DrawModes.DrawLines,
                                    ft, fN1, 0, n - 1, 1);
                grsN1T.Add(m);
            }
            if (radioN2T.Checked)
            {
                grsN2T.Clear();

                m = new MathGraphic(Color.Green, DrawModes.DrawLines,
                                    ft, fN2, 0, n - 1, 1);
                grsN2T.Add(m);
            }
            if (radioN1N2.Checked)
            {
                grsN1N2.Clear();

                grsN1N2.Add(new MathGraphic(Color.Green, DrawModes.DrawLines,
                                            fN1, fN2, 0, n - 1, 1));
                grsN1N2.Add(new MathGraphic(Color.BlueViolet, DrawModes.DrawLines,
                                            fAsympt, 0, pictureBox1.Width / zoom, (float)h));
            }

            pictureBox1.Refresh();
        }
Ejemplo n.º 10
0
Archivo: Form1.cs Proyecto: a-27m/vssdb
        private void buttonGO_Click(object sender, EventArgs e)
        {
            MathGraphic m;

            #region in/out
            try
            {
                h     = double.Parse(textBoxH.Text);
                sigma = double.Parse(textBoxSigma.Text);
                f     = double.Parse(textBoxF.Text);
                mju   = double.Parse(textBoxMju.Text);
                Y0[0] = double.Parse(textBoxA0.Text);
                Y0[1] = double.Parse(textBoxGamma0.Text);
                x1    = double.Parse(textBoxX1.Text);
                x2    = double.Parse(textBoxX2.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Wrong number format");

                textBoxH.Text      = h.ToString();
                textBoxSigma.Text  = sigma.ToString();
                textBoxF.Text      = f.ToString();
                textBoxMju.Text    = mju.ToString();
                textBoxA0.Text     = Y0[0].ToString();
                textBoxGamma0.Text = Y0[1].ToString();
                textBoxX1.Text     = x1.ToString();
                textBoxX2.Text     = x2.ToString();

                return;
            }
            #endregion

            // Y[step][variable]
            Y = RK4ST(new DoubleVectorFunction[] { a, gamma }, Y0, x1, x2, h);
            n = Y.Length;

            //for (int i = 0; i < n; i++)
            //{
            //    listBox1.Items.Add(String.Format("x: {0:F5}   a: {1:F5}   g: {2:F5}",
            //        Y[i][0], Y[i][1], Y[i][2])); // Y[step][variable]
            //}

            if (radioAT.Checked)
            {
                grsAT.Clear();

                m = new MathGraphic(Color.Green, DrawModes.DrawLines,
                                    fx, fa, 0, n - 1, 1);
                grsAT.Add(m);
            }
            if (radioGammaT.Checked)
            {
                grsGammaT.Clear();

                m = new MathGraphic(Color.Green, DrawModes.DrawLines,
                                    fx, fgamma, 0, n - 1, 1);
                grsGammaT.Add(m);
            }
            if (radioAGamma.Checked)
            {
                grsAGamma.Clear();

                m = new MathGraphic(Color.Green, DrawModes.DrawLines,
                                    fa, fgamma, 0, n - 1, 1);
                grsAGamma.Add(m);
            }

            pictureBox1.Refresh();
        }
Ejemplo n.º 11
0
 private bool ReturnTrue(MathGraphic mg)
 {
     return(true);
 }
Ejemplo n.º 12
0
Archivo: Form1.cs Proyecto: a-27m/vssdb
        private void buttonGO_Click(object sender, EventArgs e)
        {
            MathGraphic m;

            #region in/out
            try
            {
                sigma = double.Parse(textBoxSigma.Text);
                f     = double.Parse(textBoxF.Text);
                mju   = double.Parse(textBoxMju.Text);
                a1    = float.Parse(textBoxX1.Text);
                a2    = float.Parse(textBoxX2.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Wrong number format");

                textBoxSigma.Text = sigma.ToString();
                textBoxF.Text     = f.ToString();
                textBoxMju.Text   = mju.ToString();
                textBoxX1.Text    = a1.ToString();
                textBoxX2.Text    = a2.ToString();

                return;
            }
            #endregion

            List <PointF> pts = new List <PointF>();
            PointF[][]    Y;
            if (radioAS.Checked)
            {
                grsAS.Clear();

                m = new MathGraphic(Color.Green, DrawModes.DrawLines,
                                    SigmaAPlus, a, a1, a2, h);
                grsAS.Add(m);
                m = new MathGraphic(Color.Green, DrawModes.DrawLines,
                                    SigmaAMinus, a, a1, a2, h);
                grsAS.Add(m);

                Y = MathGraphic.Tabulate(SigmaAPlus, a, a1, a2, h);
                for (int i = 0; i < Y.Length; i++)
                {
                    pts.AddRange(Y[i]);
                }

                Y = MathGraphic.Tabulate(SigmaAMinus, a, a1, a2, h);
                for (int i = 0; i < Y.Length; i++)
                {
                    pts.AddRange(Y[i]);
                }
            }
            if (radioAF.Checked)
            {
                grsAF.Clear();

                m = new MathGraphic(Color.Green, DrawModes.DrawLines,
                                    fA, a, a1, a2, h);
                grsAF.Add(m);

                Y = MathGraphic.Tabulate(fA, a, a1, a2, h);
                for (int i = 0; i < Y.Length; i++)
                {
                    pts.AddRange(Y[i]);
                }
            }

            arPts = pts.ToArray();
            Array.Sort <PointF>(arPts, (Comparison <PointF>)
                                delegate(PointF A, PointF B)
            {
                return(Math.Sign(A.X - B.X));
            });

            ball = new Ball(-1, 1, 20 / zoom);
            timer1.Start();

            pictureBox1.Refresh();
        }
Ejemplo n.º 13
0
Archivo: Form1.cs Proyecto: a-27m/vssdb
        private void FindRoot()
        {
            Complex res = Complex.NaN;

            #region prepare dform
            if (dForm == null)
            {
                dForm               = new DekartForm(100, 100, 300, 300);
                dForm.ClientSize    = new Size(600, 600);
                dForm.Use_IsVisible = false;
                dForm.FormClosed   += new FormClosedEventHandler(delegate(object s, FormClosedEventArgs eva)
                {
                    dForm = null;
                });
            }
            else
            {
                dForm.RemoveAllGraphics();
            }

            #endregion

            List <Root>   roots  = new List <Root>();
            List <PointF> pts    = new List <PointF>();
            List <Color>  colors = new List <Color>();

            Color[] baseColors = new Color[] {
                Color.Red,
                Color.Orange,
                Color.Yellow,
                Color.Green,
                Color.LightBlue,
                Color.Blue,
                Color.Violet
            };

            double y1 = x1, y2 = x2;

            DoubleOfVectorFunction[] dovf = new DoubleOfVectorFunction[] { f1, f2 };
            Complex c = new Complex(0);

            for (double y = y1; y < y2; y += hy)
            {
                for (double x = x1; x < x2; x += hx)
                {
                    int   iterations;
                    float percent;
                    c.re = x;
                    c.im = y;
                    res  = Newtone(dovf, c, eps, out iterations);

                    bool inRange = true;
                    inRange &= res.re > x1;
                    inRange &= res.re < x2;
                    inRange &= res.im > y1;
                    inRange &= res.im < y2;


                    if (Complex.IsNaN(res) || !inRange)
                    {
                        colors.Add(Color.Black);
                        pts.Add(new PointF((float)x, (float)y));
                    }
                    else
                    {
                        if (roots.Count == 0)
                        {
                            Root newRoot;
                            newRoot.color = baseColors[roots.Count % baseColors.Length];
                            newRoot.value = res;
                            roots.Add(newRoot);
                        }

                        percent = iterations / 15f;
                        if (percent > 1f)
                        {
                            percent = 1f;
                        }

                        bool needAdd = true;
                        foreach (Root r in roots)
                        {
                            if (Near(r.value, res))
                            {
                                colors.Add(ColorModifer.Brightness(r.color, percent));
                                pts.Add(new PointF((float)x, (float)y));

                                needAdd = false;
                                break;
                            }
                        }

                        if (needAdd)
                        {
                            Root newRoot;
                            newRoot.color = baseColors[roots.Count % baseColors.Length];
                            newRoot.value = res;
                            roots.Add(newRoot);

                            colors.Add(ColorModifer.Brightness(newRoot.color, percent));
                            pts.Add(new PointF((float)x, (float)y));
                        }
                    }
                }
            }

            DotGraphic dotGraphic = new DotGraphic(pts.ToArray(), colors.ToArray());
            dotGraphic.CurrentColorSchema = new MathGraphic.ColorSchema(
                Color.Black, Color.DimGray, Color.DimGray, Color.Gray);
            dForm.AddGraphic(dotGraphic);

            MathGraphic mg;
            mg = new MathGraphic(Color.White, DrawModes.DrawLines, f1x, f1y,
                                 -5f, 5f, 0.01f);
            dForm.AddGraphic(mg);

            mg = new MathGraphic(Color.White, DrawModes.DrawLines, f2x, f2y,
                                 -5f, 5f, 0.01f);
            dForm.AddGraphic(mg);

            dForm.Show();
            dForm.Update2();

            foreach (Root z in roots)
            {
                listRoots.Items.Add("z" + (listRoots.Items.Count + 1) + " = "
                                    + z.value.ToString("F6"));
                listY.Items.Add("f,g" + (listY.Items.Count + 1) + " = "
                                + f1(z.value.re, z.value.im).ToString("F6") + ", "
                                + f2(z.value.re, z.value.im).ToString("F6"));
            }
        }