Beispiel #1
0
        public static DataSource CreateCircularField2(int width, int height)
        {
            var vectorArray = DataSource2DHelper.CreateVectorData(width, height, (x, y) =>
            {
                Vector result;

                double xc = x - width / 2;
                double yc = y - height / 2;
                if (xc != 0)
                {
                    double beta  = Math.Sqrt(1.0 / (1 + yc * yc / (xc * xc)));
                    double alpha = -beta * yc / xc;
                    result       = new Vector(alpha, beta);
                }
                else
                {
                    double alpha = Math.Sqrt(1.0 / (1 + xc * xc / (yc * yc)));
                    double beta  = -alpha * xc / yc;
                    result       = new Vector(alpha, beta);
                }

                if (Double.IsNaN(result.X))
                {
                    result = new Vector(0, 0);
                }

                return(result);
            });

            return(CreateVectorField(width, height, vectorArray));
        }
        private static Vector[,] CreateCircleField()
        {
            return(DataSource2DHelper.CreateVectorData(width, height, (x, y) =>
            {
                Vector result;

                double xc = x - width / 2;
                double yc = y - height / 2;
                if (xc != 0)
                {
                    double beta = Math.Sqrt(1.0 / (1 + yc * yc / (xc * xc)));
                    double alpha = -beta * yc / xc;
                    result = new Vector(alpha, beta);
                }
                else
                {
                    double alpha = Math.Sqrt(1.0 / (1 + xc * xc / (yc * yc)));
                    double beta = -alpha * xc / yc;
                    result = new Vector(alpha, beta);
                }

                if (Double.IsNaN(result.X))
                {
                    result = new Vector(0, 0);
                }

                return result;
            }));
        }
 private static Vector[,] CreateCheсkerboard()
 {
     return(DataSource2DHelper.CreateVectorData(width, height, (x, y) =>
     {
         var result = (x / 40) % 2 - (y / 40) % 2 == 0 ? new Vector(x + 1, 0) : new Vector(0, y + 1);
         return result;
     }));
 }
        public static DataSource CreateTangentPotentialField(PotentialField field, int width = 200, int height = 200)
        {
            var vectorArray = DataSource2DHelper.CreateVectorData(width, height, (x, y) =>
            {
                return(field.GetTangentVector(new Point(x, y)));
            });

            return(CreateVectorField(width, height, vectorArray));
        }
        public static DataSource CreateCheckerboard(int width = 100, int height = 100, int cellSize = 40)
        {
            var vectorArray = DataSource2DHelper.CreateVectorData(width, height, (x, y) =>
            {
                var result = (x / cellSize) % 2 - (y / cellSize) % 2 == 0 ? new Vector(1, 0) : new Vector(0, 1);
                return(result);
            });

            return(CreateVectorField(width, height, vectorArray));
        }
Beispiel #6
0
        public static DataSource CreateCheckerboard(int width, int height)
        {
            var vectorArray = DataSource2DHelper.CreateVectorData(width, height, (x, y) =>
            {
                var result = (x / 40) % 2 - (y / 40) % 2 == 0 ? new Vector(x + 1, 0) : new Vector(0, y + 1);
                return(result);
            });

            return(CreateVectorField(width, height, vectorArray));
        }
        public static DataSource CreateTangentPotentialField(int width = 200, int height = 200, params PotentialPoint[] points)
        {
            var potentialField = new PotentialField();

            potentialField.AddPoints(points);
            var vectorArray = DataSource2DHelper.CreateVectorData(width, height, (x, y) =>
            {
                return(potentialField.GetTangentVector(new Point(x, y)));
            });

            return(CreateVectorField(width, height, vectorArray));
        }
        public static Vector[,] CreatePotentialField()
        {
            PotentialField field = new PotentialField();

            field.AddPotentialPoint(0, 0, 1);
            field.AddPotentialPoint(20, 30, -1);
            field.AddPotentialPoint(50, 100, 1);
            field.AddPotentialPoint(100, 200, 3);

            return(DataSource2DHelper.CreateVectorData(width, height, (x, y) =>
            {
                return field.GetPotential(new Point(x, y));
            }));
        }
Beispiel #9
0
        private WarpedDataSource2D <Vector> LoadVectorField()
        {
            Random    rnd   = new Random();
            const int count = 20;
            var       grid  = DataSource2DHelper.CreateUniformGrid(count, count, 1, 1);
            var       data  = DataSource2DHelper.CreateVectorData(count, count, (x, y) =>
            {
                const double scale = Math.PI;
                return(new Vector(Math.Sin(scale * rnd.NextDouble()), Math.Sin(scale * rnd.NextDouble())) / count / 2);
            });

            WarpedDataSource2D <Vector> dataSource = new WarpedDataSource2D <Vector>(data, grid);

            return(dataSource);
        }
        public static Vector[,] CreateCircleField2()
        {
            return(DataSource2DHelper.CreateVectorData(width, height, (x, y) =>
            {
                Vector3D center = new Vector3D(width / 2f, height / 2f, 0);
                Vector3D up = new Vector3D(0, 0, 1);
                Vector3D vec = center - new Vector3D(x, y, 0);
                Vector3D tangent = Vector3D.CrossProduct(vec, up);
                Vector value = new Vector(tangent.X, tangent.Y);
                //if (value.X != 0 || value.Y != 0)
                //    value.Normalize();

                return value;
            }));
        }
Beispiel #11
0
        public static DataSource CreateCircularField(int width, int height)
        {
            var vectorArray = DataSource2DHelper.CreateVectorData(width, height, (x, y) =>
            {
                Vector3D center  = new Vector3D(width / 2f, height / 2f, 0);
                Vector3D up      = new Vector3D(0, 0, 1);
                Vector3D vec     = center - new Vector3D(x, y, 0);
                Vector3D tangent = Vector3D.CrossProduct(vec, up);
                Vector value     = new Vector(tangent.X, tangent.Y);
                //if (value.X != 0 || value.Y != 0)
                //    value.Normalize();

                return(value);
            });

            return(CreateVectorField(width, height, vectorArray));
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            int width  = 200;
            int height = 200;

            Vector[,] data =
                DataSource2DHelper.CreateVectorData(width, height, (x, y) => ((int)(x / 40)) % 2 == 0 && ((int)(y / 40)) % 2 == 0 ? new Vector(1, 0) : new Vector(0, 1));
            //DataSource2DHelper.CreateVectorData(width, height, (ix, iy) => new Vector(Math.Sin(((double)ix) / 30), Math.Cos(((double)iy) / 30)));
            //DataSource2DHelper.CreateVectorData(width, height, (x, y) =>
            //{
            //    Vector result;

            //    double xc = x - width / 2;
            //    double yc = y - height / 2;
            //    if (xc != 0)
            //    {
            //        double beta = Math.Sqrt(1.0 / (1 + yc * yc / (xc * xc)));
            //        double alpha = -beta * yc / xc;
            //        result = new Vector(alpha, beta);
            //    }
            //    else
            //    {
            //        double alpha = Math.Sqrt(1.0 / (1 + xc * xc / (yc * yc)));
            //        double beta = -alpha * xc / yc;
            //        result = new Vector(alpha, beta);
            //    }

            //    if (Double.IsNaN(result.X))
            //    {
            //        result = new Vector(0, 0);
            //    }

            //    return result;
            //});

            double[] xs = Enumerable.Range(0, width).Select(i => (double)i).ToArray();
            double[] ys = Enumerable.Range(0, height).Select(i => (double)i).ToArray();

            var dataSource = new NonUniformDataSource2D <Vector>(xs, ys, data);

            DataContext = dataSource;
        }