Exemple #1
0
        public static Plot2D PlotField(string formula, float minX, float maxX, float minY, float maxY, Color color)
        {
            Plot2D plot2D = new Plot2D();
            var    x1     = minX;
            var    num1   = (float)(1.0 / 800.0 * (maxX - (double)minX));
            var    num2   = (float)(1.0 / 800.0 * (maxY - (double)minY));

            if (num1 < 0.0 || num2 < 0.0)
            {
                throw new ArgumentException("max<min !");
            }
            Onp onp        = new Onp();
            var onPformula = onp.Parse(formula);
            var x2         = new Dictionary <char, double>(2)
            {
                { 'x', 0.0 }, { 'y', 0.0 }
            };

            while (x1 <= (double)maxX)
            {
                x2['x'] = x1;
                var y = minY;
                while (y <= (double)maxY)
                {
                    x2['y'] = y;
                    if (onp.Solve(onPformula, x2) > 0.0)
                    {
                        plot2D._points.Add(new PPoint2D(x1, y, color));
                    }
                    y += num2;
                }
                x1 += num1;
            }
            return(plot2D);
        }
Exemple #2
0
        public static Plot2D PlotField(string formula, Range xx, Range yy, Color color)
        {
            Plot2D plot2D = new Plot2D();
            var    x1     = xx.Min;

            if (xx.Diff < 0.0 || yy.Diff < 0.0)
            {
                throw new ArgumentException("max<min !");
            }
            Onp onp        = new Onp();
            var onPformula = onp.Parse(formula);
            var x2         = new Dictionary <char, double>(2)
            {
                { 'x', 0.0 }, { 'y', 0.0 }
            };

            while (x1 <= (double)xx.Max)
            {
                x2['x'] = x1;
                var y = yy.Min;
                while (y <= (double)yy.Max)
                {
                    x2['y'] = y;
                    if (onp.Solve(onPformula, x2) > 0.0)
                    {
                        plot2D._points.Add(new PPoint2D(x1, y, color));
                    }
                    y += yy.Diff;
                }
                x1 += xx.Diff;
            }
            return(plot2D);
        }
Exemple #3
0
        public static Plot2D ReuleauxPolygonF(float dx, int n, float scale, Color color)
        {
            Plot2D plot2D = new Plot2D();
            var    num1   = 0.0f;

            while (num1 <= 2.0 * Math.PI)
            {
                var num2 =
                    (float)
                    (2.0 * Math.Cos(Math.PI / (2 * n)) *
                     Math.Cos(0.5 * (num1 + Math.PI / n * (2.0 * Math.Floor(n * (double)num1 / (2.0 * Math.PI)) + 1.0))) -
                     Math.Cos(Math.PI / n * (2.0 * Math.Floor(n * (double)num1 / (2.0 * Math.PI)) + 1.0)));
                var num3 =
                    (float)
                    (2.0 * Math.Cos(Math.PI / (2 * n)) *
                     Math.Sin(0.5 * (num1 + Math.PI / n * (2.0 * Math.Floor(n * (double)num1 / (2.0 * Math.PI)) + 1.0))) -
                     Math.Sin(Math.PI / n * (2.0 * Math.Floor(n * (double)num1 / (2.0 * Math.PI)) + 1.0)));
                var num4 = (float)Math.Sqrt(num2 * (double)num2 + num3 * (double)num3);
                var num5 = num2 / num4;
                var num6 = num3 / num4;
                var num7 = num4 * scale;
                var num8 = dx;
                while (num8 <= (double)num7)
                {
                    plot2D.AddPoint(new PPoint2D(num5 * num8, num6 * num8, color));
                    num8 += dx;
                }
                num1 += dx;
            }
            return(plot2D);
        }
Exemple #4
0
        public static Plot2D operator +(PPoint2D a, PPoint2D b)
        {
            Plot2D   plot2D = new Plot2D();
            PPoint2D p1     = a;

            plot2D.AddPoint(p1);
            PPoint2D p2 = b;

            plot2D.AddPoint(p2);
            return(plot2D);
        }
Exemple #5
0
        public static Plot2D Ellipse(float dx, float a, float b, Color color)
        {
            Plot2D plot2D = new Plot2D();
            var    num    = 0.0f;

            while (num <= 2.0 * Math.PI)
            {
                plot2D.AddPoint(new PPoint2D((float)Math.Cos(num) * a, (float)Math.Sin(num) * b, color));
                num += dx;
            }
            return(plot2D);
        }
Exemple #6
0
        public static Plot2D PlotParametric(string fX, string fY, char[] vars, Range[] ranges, Color color)
        {
            Plot2D p   = new Plot2D();
            Onp    o   = new Onp();
            var    fX1 = o.Parse(fX);
            var    fY1 = o.Parse(fY);
            var    d   = new Dictionary <char, double>();

            foreach (var var in vars)
            {
                d.Add(var, 0.0);
            }
            PlotP(o, fX1, fY1, vars, ranges, p, d, 0, color);
            return(p);
        }
Exemple #7
0
        public static Plot2D Line2D(float dx, PPoint2D a, PPoint2D b, Color color)
        {
            Plot2D plot2D = new Plot2D();
            var    num1   = a.X - b.X;
            var    num2   = a.Y - b.Y;
            var    num3   = (float)Math.Sqrt(num1 * (double)num1 + num2 * (double)num2);
            var    num4   = num1 / num3;
            var    num5   = num2 / num3;
            var    num6   = 0.0f;

            while (num6 <= (double)num3)
            {
                plot2D.AddPoint(new PPoint2D(num6 * num4 + b.X, num6 * num5 + b.Y, color));
                num6 += dx;
            }
            return(plot2D);
        }
Exemple #8
0
        public static Plot2D RectangleF(float dx, float a, float b, Color color)
        {
            Plot2D plot2D = new Plot2D();
            var    x      = 0.0f;

            while (x <= (double)a)
            {
                var y = 0.0f;
                while (y <= (double)b)
                {
                    plot2D.AddPoint(new PPoint2D(x, y, color));
                    y += dx;
                }
                x += dx;
            }
            return(plot2D);
        }
Exemple #9
0
        public static Plot2D CircleF(float dx, float r, Color color)
        {
            Plot2D plot2D = new Plot2D();
            var    num1   = 0.0f;

            while (num1 <= 2.0 * Math.PI)
            {
                var num2 = (float)Math.Cos(num1);
                var num3 = (float)Math.Sin(num1);
                var num4 = dx;
                while (num4 <= (double)r)
                {
                    plot2D.AddPoint(new PPoint2D(num2 * num4, num3 * num4, color));
                    num4 += dx;
                }
                num1 += dx;
            }
            return(plot2D);
        }
Exemple #10
0
        public static Plot2D operator +(Plot2D a, Plot2D b)
        {
            Plot2D plot2D = new Plot2D();

            plot2D._points.AddRange(a._points);
            plot2D._points.AddRange(b._points);
            var num1 = (a.Size + (double)b.Size) * 0.5;

            plot2D.Size = (float)num1;
            var num2 = !a.Connect ? 0 : (b.Connect ? 1 : 0);

            plot2D.Connect = num2 != 0;
            var num3 = (a.LinesH + (double)b.LinesH) * 0.5;

            plot2D.LinesH = (float)num3;
            var num4 = (a.LinesV + (double)b.LinesV) * 0.5;

            plot2D.LinesV = (float)num4;
            return(plot2D);
        }
Exemple #11
0
        public static Plot2D operator +(Plot2D a, PPoint2D b)
        {
            Plot2D plot2D = new Plot2D();

            plot2D._points.AddRange(a._points);
            plot2D._points.Add(b);
            double num1 = a.Size;

            plot2D.Size = (float)num1;
            var num2 = a.Connect ? 1 : 0;

            plot2D.Connect = num2 != 0;
            double num3 = a.LinesH;

            plot2D.LinesH = (float)num3;
            double num4 = a.LinesV;

            plot2D.LinesV = (float)num4;
            return(plot2D);
        }
Exemple #12
0
        public static Plot2D PlotFunction(string formula, Range xx, Color color)
        {
            Plot2D plot2D = new Plot2D {
                Connect = true
            };
            var x = xx.Min;

            if (xx.Diff < 0.0)
            {
                throw new ArgumentException("maxX<minX !");
            }
            Onp onp        = new Onp();
            var onPformula = onp.Parse(formula);

            while (x <= (double)xx.Max)
            {
                plot2D._points.Add(new PPoint2D(x, (float)onp.Solve(onPformula, x), color));
                x += xx.Diff;
            }
            return(plot2D);
        }
Exemple #13
0
        public static Plot2D PlotFunction(string formula, float minX, float maxX, Color color)
        {
            Plot2D plot2D = new Plot2D {
                Connect = true
            };
            var x   = minX;
            var num = (float)(1.0 / 800.0 * (maxX - (double)minX));

            if (num < 0.0)
            {
                throw new ArgumentException("maxX<minX !");
            }
            Onp onp        = new Onp();
            var onPformula = onp.Parse(formula);

            while (x <= (double)maxX)
            {
                plot2D._points.Add(new PPoint2D(x, (float)onp.Solve(onPformula, x), color));
                x += num;
            }
            return(plot2D);
        }
Exemple #14
0
        public static Plot2D ReuleauxPolygon(float dx, int n, float scale, Color color)
        {
            Plot2D plot2D = new Plot2D();
            var    num1   = 0.0f;

            while (num1 <= 2.0 * Math.PI)
            {
                var num2 =
                    (float)
                    (2.0 * Math.Cos(Math.PI / (2 * n)) *
                     Math.Cos(0.5 * (num1 + Math.PI / n * (2.0 * Math.Floor(n * (double)num1 / (2.0 * Math.PI)) + 1.0))) -
                     Math.Cos(Math.PI / n * (2.0 * Math.Floor(n * (double)num1 / (2.0 * Math.PI)) + 1.0)));
                var num3 =
                    (float)
                    (2.0 * Math.Cos(Math.PI / (2 * n)) *
                     Math.Sin(0.5 * (num1 + Math.PI / n * (2.0 * Math.Floor(n * (double)num1 / (2.0 * Math.PI)) + 1.0))) -
                     Math.Sin(Math.PI / n * (2.0 * Math.Floor(n * (double)num1 / (2.0 * Math.PI)) + 1.0)));
                plot2D.AddPoint(new PPoint2D(num2 * scale, num3 * scale, color));
                num1 += dx;
            }
            return(plot2D);
        }
Exemple #15
0
        public static Plot2D EllipseF(float dx, float a, float b, Color color)
        {
            Plot2D plot2D = new Plot2D();
            var    num1   = 0.0f;

            while (num1 <= 2.0 * Math.PI)
            {
                var num2 = (float)Math.Cos(num1) * a;
                var num3 = (float)Math.Sin(num1) * b;
                var num4 = (float)Math.Sqrt(num2 * (double)num2 + num3 * (double)num3);
                var num5 = num2 / num4;
                var num6 = num3 / num4;
                var num7 = dx;
                while (num7 <= (double)num4)
                {
                    plot2D.AddPoint(new PPoint2D(num5 * num7, num6 * num7, color));
                    num7 += dx;
                }
                num1 += dx;
            }
            return(plot2D);
        }
Exemple #16
0
 private static void PlotP(Onp o, Queue <string> fX, Queue <string> fY, IReadOnlyList <char> vars,
                           IReadOnlyList <Range> ranges, Plot2D p, Dictionary <char, double> d, int a, Color color)
 {
     if (a >= vars.Count - 1)
     {
         var num = ranges[a].Min;
         while (num <= (double)ranges[a].Max)
         {
             d[vars[a]] = num;
             p.AddPoint(new PPoint2D((float)o.Solve(fX, d), (float)o.Solve(fY, d), color));
             num += ranges[a].Diff;
         }
     }
     else
     {
         var num = ranges[a].Min;
         while (num <= (double)ranges[a].Max)
         {
             d[vars[a]] = num;
             PlotP(o, fX, fY, vars, ranges, p, d, a + 1, color);
             num += ranges[a].Diff;
         }
     }
 }