예제 #1
0
            private static Point GenerateRandomPointAround(Point P, float MinDist, DefaultRandom Generator)
            {
                // start with non-uniform distribution
                float R1 = Generator.RandomFloat();
                float R2 = Generator.RandomFloat();

                // radius should be between MinDist and 2 * MinDist
                float Radius = MinDist * (R1 + 1.0f);

                // random angle
                float Angle = 2 * 3.141592653589f * R2;

                // the new point is generated around the point (x, y)
                float X = (float)(P.x + Radius * Math.Cos(Angle));
                float Y = (float)(P.y + Radius * Math.Sin(Angle));

                return(new Point(X, Y));
            }
예제 #2
0
            public static float[,] Generate(int NumPoints = 0, float MinDist = -1f,
                                            bool Circle   = true, int NewPointsCount = 30)
            {
                if (MinDist <= 0.0f && NumPoints <= 0)
                {
                    NumPoints = 2000;
                }
                if (MinDist <= 0.0f)
                {
                    MinDist = (float)Math.Sqrt((float)NumPoints) / NumPoints;
                }
                if (NumPoints <= 0)
                {
                    NumPoints = (int)(1 / (MinDist * MinDist));
                }

                var Generator    = new DefaultRandom();
                var SamplePoints = new List <Point>();
                var ProcessList  = new List <Point>();

                // create the grid
                float CellSize = MinDist / (float)Math.Sqrt(2.0f);

                int GridW = (int)Math.Ceiling(1.0f / CellSize);
                int GridH = (int)Math.Ceiling(1.0f / CellSize);

                Grid Grid = new Grid(GridW, GridH, CellSize);

                Point FirstPoint;

                do
                {
                    FirstPoint = new Point(Generator.RandomFloat(), Generator.RandomFloat());
                } while (!(Circle ? FirstPoint.IsInCircle() : FirstPoint.IsInRectangle()));

                // update containers
                ProcessList.Add(FirstPoint);
                SamplePoints.Add(FirstPoint);
                Grid.Insert(FirstPoint);

                // generate new points for each point in the queue
                while (ProcessList.Count > 0 && SamplePoints.Count < NumPoints)
                {
                    Point Point = PopRandom(ProcessList, Generator);

                    for (int i = 0; i < NewPointsCount; i++)
                    {
                        Point NewPoint = GenerateRandomPointAround(Point, MinDist, Generator);

                        bool Fits = Circle ? NewPoint.IsInCircle() : NewPoint.IsInRectangle();

                        if (Fits && !Grid.IsInNeighbourhood(NewPoint, MinDist, CellSize))
                        {
                            ProcessList.Add(NewPoint);
                            SamplePoints.Add(NewPoint);
                            Grid.Insert(NewPoint);
                            continue;
                        }
                    }
                }

                var result = new float[SamplePoints.Count, 2];

                for (int i = 0; i < SamplePoints.Count; i++)
                {
                    result[i, 0] = SamplePoints[i].x * 2 - 1;
                    result[i, 1] = SamplePoints[i].y * 2 - 1;
                }

                return(result);
            }
예제 #3
0
            public static float[,] Generate(int NumPoints = 0, float MinDist = -1f,
                bool Circle = true, int NewPointsCount = 30)
            {
                if (MinDist <= 0.0f && NumPoints <= 0)
                    NumPoints = 2000;
                if (MinDist <= 0.0f)
                    MinDist = (float)Math.Sqrt((float)NumPoints) / NumPoints;
                if (NumPoints <= 0)
                    NumPoints = (int)(1 / (MinDist * MinDist));

                var Generator = new DefaultRandom();
                var SamplePoints = new List<Point>();
                var ProcessList = new List<Point>();

                // create the grid
                float CellSize = MinDist / (float)Math.Sqrt(2.0f);

                int GridW = (int)Math.Ceiling(1.0f / CellSize);
                int GridH = (int)Math.Ceiling(1.0f / CellSize);

                Grid Grid = new Grid(GridW, GridH, CellSize);

                Point FirstPoint;
                do
                {
                    FirstPoint = new Point(Generator.RandomFloat(), Generator.RandomFloat());
                } while (!(Circle ? FirstPoint.IsInCircle() : FirstPoint.IsInRectangle()));

                // update containers
                ProcessList.Add(FirstPoint);
                SamplePoints.Add(FirstPoint);
                Grid.Insert(FirstPoint);

                // generate new points for each point in the queue
                while (ProcessList.Count > 0 && SamplePoints.Count < NumPoints)
                {
                    Point Point = PopRandom(ProcessList, Generator);

                    for (int i = 0; i < NewPointsCount; i++)
                    {
                        Point NewPoint = GenerateRandomPointAround(Point, MinDist, Generator);

                        bool Fits = Circle ? NewPoint.IsInCircle() : NewPoint.IsInRectangle();

                        if (Fits && !Grid.IsInNeighbourhood(NewPoint, MinDist, CellSize))
                        {
                            ProcessList.Add(NewPoint);
                            SamplePoints.Add(NewPoint);
                            Grid.Insert(NewPoint);
                            continue;
                        }
                    }
                }

                var result = new float[SamplePoints.Count, 2];
                for (int i = 0; i < SamplePoints.Count; i++)
                {
                    result[i, 0] = SamplePoints[i].x * 2 - 1;
                    result[i, 1] = SamplePoints[i].y * 2 - 1;
                }

                return result;
            }
예제 #4
0
            private static Point GenerateRandomPointAround(Point P, float MinDist, DefaultRandom Generator )
            {
                // start with non-uniform distribution
                float R1 = Generator.RandomFloat();
                float R2 = Generator.RandomFloat();

                // radius should be between MinDist and 2 * MinDist
                float Radius = MinDist * (R1 + 1.0f);

                // random angle
                float Angle = 2 * 3.141592653589f * R2;

                // the new point is generated around the point (x, y)
                float X = (float)(P.x + Radius * Math.Cos(Angle));
                float Y = (float)(P.y + Radius * Math.Sin(Angle));

                return new Point(X, Y);
            }