Пример #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);
        }
Пример #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);
        }
Пример #3
0
 private static void PlotP(Onp o, Queue <string> fX, Queue <string> fY, Queue <string> fZ, char[] vars,
                           Range[] ranges, Plot3D p, Dictionary <char, double> d, int a, Color color)
 {
     if (a >= vars.Length - 1)
     {
         var num = ranges[a].Min;
         while (num <= (double)ranges[a].Max)
         {
             d[vars[a]] = num;
             p.AddPoint(new PPoint3D((float)o.Solve(fX, d), (float)o.Solve(fY, d), (float)o.Solve(fZ, 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, fZ, vars, ranges, p, d, a + 1, color);
             num += ranges[a].Diff;
         }
     }
 }
Пример #4
0
        public static Plot3D PlotField(string formula, float minX, float maxX, float minY, float maxY, float minZ,
                                       float maxZ, Color color)
        {
            Plot3D plot3D = new Plot3D();
            var    x1     = minX;
            var    num1   = (float)(1.0 / 800.0 * (maxX - (double)minX));
            var    num2   = (float)(1.0 / 800.0 * (maxY - (double)minY));
            var    num3   = (float)(1.0 / 800.0 * (maxZ - (double)minZ));

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

            while (x1 <= (double)maxX)
            {
                x2['x'] = x1;
                var y = minY;
                while (y <= (double)maxY)
                {
                    x2['y'] = y;
                    var z = minZ;
                    while (z <= (double)maxZ)
                    {
                        x2['z'] = z;
                        if (onp.Solve(onPformula, x2) > 0.0)
                        {
                            if (z > (double)plot3D.MaxZ)
                            {
                                plot3D.MaxZ = z;
                            }
                            if (z < (double)plot3D.MinZ)
                            {
                                plot3D.MinZ = z;
                            }
                            plot3D._points.Add(new PPoint3D(x1, y, z, color));
                        }
                        z += num3;
                    }
                    y += num2;
                }
                x1 += num1;
            }
            return(plot3D);
        }
Пример #5
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);
        }
Пример #6
0
        public static Plot3D PlotField(string formula, Range xx, Range yy, Range zz, Color color)
        {
            Plot3D plot3D = new Plot3D();
            var    x1     = xx.Min;

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

            while (x1 <= (double)xx.Max)
            {
                x2['x'] = x1;
                var y = yy.Min;
                while (y <= (double)yy.Max)
                {
                    x2['y'] = y;
                    var z = zz.Min;
                    while (z <= (double)zz.Max)
                    {
                        x2['z'] = z;
                        if (onp.Solve(onPformula, x2) > 0.0)
                        {
                            if (z > (double)plot3D.MaxZ)
                            {
                                plot3D.MaxZ = z;
                            }
                            if (z < (double)plot3D.MinZ)
                            {
                                plot3D.MinZ = z;
                            }
                            plot3D._points.Add(new PPoint3D(x1, y, z, color));
                        }
                        z += zz.Diff;
                    }
                    y += yy.Diff;
                }
                x1 += xx.Diff;
            }
            return(plot3D);
        }
Пример #7
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);
        }
Пример #8
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);
        }
Пример #9
0
        public static Plot3D PlotFunction(string formula, Range xx, Range yy)
        {
            Plot3D plot3D = new Plot3D();
            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;
                    var z = (float)onp.Solve(onPformula, x2);
                    if (z > (double)plot3D.MaxZ)
                    {
                        plot3D.MaxZ = z;
                    }
                    if (z < (double)plot3D.MinZ)
                    {
                        plot3D.MinZ = z;
                    }
                    plot3D._points.Add(new PPoint3D(x1, y, z));
                    y += yy.Diff;
                }
                x1 += xx.Diff;
            }
            return(plot3D);
        }
Пример #10
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;
         }
     }
 }
Пример #11
0
 public OnpTester()
 {
     _onp = new Onp();
 }