Example #1
0
        public static Plot3D Cuboid(float dx, float a, float b, float c, Color color)
        {
            Plot3D plot3D = new Plot3D();
            var    x      = 0.0f;

            while (x <= (double)a)
            {
                plot3D.AddPoint(new PPoint3D(x, 0.0f, 0.0f, color));
                plot3D.AddPoint(new PPoint3D(x, b, 0.0f, color));
                plot3D.AddPoint(new PPoint3D(x, 0.0f, c, color));
                plot3D.AddPoint(new PPoint3D(x, b, c, color));
                x += dx;
            }
            var y = 0.0f;

            while (y <= (double)b)
            {
                plot3D.AddPoint(new PPoint3D(0.0f, y, 0.0f, color));
                plot3D.AddPoint(new PPoint3D(a, y, 0.0f, color));
                plot3D.AddPoint(new PPoint3D(0.0f, y, c, color));
                plot3D.AddPoint(new PPoint3D(a, y, c, color));
                y += dx;
            }
            var z = 0.0f;

            while (z <= (double)c)
            {
                plot3D.AddPoint(new PPoint3D(0.0f, 0.0f, z, color));
                plot3D.AddPoint(new PPoint3D(a, 0.0f, z, color));
                plot3D.AddPoint(new PPoint3D(0.0f, b, z, color));
                plot3D.AddPoint(new PPoint3D(a, b, z, color));
                z += dx;
            }
            return(plot3D);
        }
Example #2
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;
         }
     }
 }
Example #3
0
        public static Plot3D EllipsoidF(float dx, float a, float b, float c, Color color)
        {
            Plot3D plot3D = new Plot3D();
            var    num1   = 0.0f;

            while (num1 <= Math.PI)
            {
                var num2 = 0.0f;
                while (num2 <= 2.0 * Math.PI)
                {
                    var num3  = (float)(Math.Sin(num1) * Math.Cos(num2)) * a;
                    var num4  = (float)(Math.Sin(num1) * Math.Sin(num2)) * b;
                    var num5  = (float)Math.Cos(num1) * c;
                    var num6  = (float)Math.Sqrt(num3 * (double)num3 + num4 * (double)num4 + num5 * (double)num5);
                    var num7  = num3 / num6;
                    var num8  = num4 / num6;
                    var num9  = num5 / num6;
                    var num10 = dx;
                    while (num10 <= (double)num6)
                    {
                        plot3D.AddPoint(new PPoint3D(num7 * num10, num8 * num10, num9 * num10, color));
                        num10 += dx;
                    }
                    num2 += dx;
                }
                num1 += dx;
            }
            return(plot3D);
        }
Example #4
0
        public static Plot3D SphereF(float dx, float r, Color color)
        {
            Plot3D plot3D = new Plot3D();
            var    num1   = 0.0f;

            while (num1 <= Math.PI)
            {
                var num2 = 0.0f;
                while (num2 <= 2.0 * Math.PI)
                {
                    var num3 = (float)(Math.Sin(num1) * Math.Cos(num2));
                    var num4 = (float)(Math.Sin(num1) * Math.Sin(num2));
                    var num5 = (float)Math.Cos(num1);
                    var num6 = dx;
                    while (num6 <= (double)r)
                    {
                        plot3D.AddPoint(new PPoint3D(num3 * num6, num4 * num6, num5 * num6, color));
                        num6 += dx;
                    }
                    num2 += dx;
                }
                num1 += dx;
            }
            return(plot3D);
        }
Example #5
0
        public static Plot3D operator +(Plot3D a, PPoint3D b)
        {
            Plot3D plot3D = new Plot3D();

            plot3D._points.AddRange(a._points);
            plot3D._points.Add(b);
            double num = a.Size;

            plot3D.Size = (float)num;
            return(plot3D);
        }
Example #6
0
        public static Plot3D operator +(PPoint3D a, PPoint3D b)
        {
            Plot3D   plot3D = new Plot3D();
            PPoint3D p1     = a;

            plot3D.AddPoint(p1);
            PPoint3D p2 = b;

            plot3D.AddPoint(p2);
            return(plot3D);
        }
Example #7
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);
        }
Example #8
0
        public static Plot3D operator +(Plot3D a, Plot3D b)
        {
            Plot3D plot3D = new Plot3D();

            plot3D._points.AddRange(a._points);
            plot3D._points.AddRange(b._points);
            plot3D.MaxZ   = a.MaxZ <= (double)b.MaxZ ? b.MaxZ : a.MaxZ;
            plot3D.MinZ   = a.MinZ >= (double)b.MinZ ? b.MinZ : a.MinZ;
            plot3D.Size   = (float)((a.Size + (double)b.Size) * 0.5);
            plot3D.LinesH = (float)((a.LinesH + (double)b.LinesH) * 0.5);
            plot3D.LinesV = (float)((a.LinesV + (double)b.LinesV) * 0.5);
            plot3D.LinesL = (float)((a.LinesL + (double)b.LinesL) * 0.5);
            return(plot3D);
        }
Example #9
0
        public static Plot3D PlotParametric(string fX, string fY, string fZ, char[] vars, Range[] ranges, Color color)
        {
            Plot3D p   = new Plot3D();
            Onp    o   = new Onp();
            var    fX1 = o.Parse(fX);
            var    fY1 = o.Parse(fY);
            var    fZ1 = o.Parse(fZ);
            var    d   = new Dictionary <char, double>();

            foreach (var var in vars)
            {
                d.Add(var, 0.0);
            }
            PlotP(o, fX1, fY1, fZ1, vars, ranges, p, d, 0, color);
            return(p);
        }
Example #10
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);
        }
Example #11
0
        public static Plot3D Ellipsoid(float dx, float a, float b, float c, Color color)
        {
            Plot3D plot3D = new Plot3D();
            var    num1   = 0.0f;

            while (num1 <= Math.PI)
            {
                var num2 = 0.0f;
                while (num2 <= 2.0 * Math.PI)
                {
                    plot3D.AddPoint(new PPoint3D((float)(Math.Sin(num1) * Math.Cos(num2)) * a,
                                                 (float)(Math.Sin(num1) * Math.Sin(num2)) * b, (float)Math.Cos(num1) * c, color));
                    num2 += dx;
                }
                num1 += dx;
            }
            return(plot3D);
        }
Example #12
0
        public static Plot3D Sphere(float dx, float r, Color color)
        {
            Plot3D plot3D = new Plot3D();
            var    num1   = 0.0f;

            while (num1 <= Math.PI)
            {
                var num2 = 0.0f;
                while (num2 <= 2.0 * Math.PI)
                {
                    plot3D.AddPoint(new PPoint3D((float)(Math.Sin(num1) * Math.Cos(num2)) * r,
                                                 (float)(Math.Sin(num1) * Math.Sin(num2)) * r, (float)Math.Cos(num1) * r, color));
                    num2 += dx;
                }
                num1 += dx;
            }
            return(plot3D);
        }
Example #13
0
        public static Plot3D Line3D(float dx, PPoint3D a, PPoint3D b, Color color)
        {
            Plot3D plot3D = new Plot3D();
            var    num1   = a.X - b.X;
            var    num2   = a.Y - b.Y;
            var    num3   = a.Z - b.Z;
            var    num4   = (float)Math.Sqrt(num1 * (double)num1 + num2 * (double)num2 + num3 * (double)num3);
            var    num5   = num1 / num4;
            var    num6   = num2 / num4;
            var    num7   = num3 / num4;
            var    num8   = 0.0f;

            while (num8 <= (double)num4)
            {
                plot3D.AddPoint(new PPoint3D(num8 * num5 + b.X, num8 * num6 + b.Y, num8 * num7 + b.Z, color));
                num8 += dx;
            }
            return(plot3D);
        }
Example #14
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);
        }
Example #15
0
        public static Plot3D CuboidF(float dx, float a, float b, float c, Color color)
        {
            Plot3D plot3D = new Plot3D();
            var    x      = 0.0f;

            while (x <= (double)a)
            {
                var y = 0.0f;
                while (y <= (double)b)
                {
                    var z = 0.0f;
                    while (z <= (double)c)
                    {
                        plot3D.AddPoint(new PPoint3D(x, y, z, color));
                        z += dx;
                    }
                    y += dx;
                }
                x += dx;
            }
            return(plot3D);
        }