예제 #1
0
        private void Update()
        {
            if (ToggleToGenerate != _previous)
            {
                _points = GenerateMemoryRandomSet2D(GenerateRadius, GenerateCountMin, GenerateCountMax, CoeffX, CoeffY);

                bool created = ConvexHull.Create2D(_points, out _indices, out _dim);
                Logger.LogInfo("Created: " + created + "   Dimension: " + _dim);

                if (CreateMeshObject)
                {
                    CreateMesh();
                }
            }
            _previous = ToggleToGenerate;
        }
예제 #2
0
        public static RectangleOriented FindMbrBoxByArea(List <PointD> list_of_points)
        {
            if (list_of_points.Count <= 1)
            {
                return(new RectangleOriented(new PointD(0, 0), 0, 0, 0));
            }

            ConvexHullCreationResult <DefaultVertex2D> hull = ConvexHull.Create2D(list_of_points.Select(x => new double[2] {
                x.X, x.Y
            }).ToList());

            double[,] hull_array = new double[hull.Result.Count, 2];

            for (int i = 0; i < hull.Result.Count; i++)
            {
                hull_array[i, 0] = hull.Result[i].X;
                hull_array[i, 1] = hull.Result[i].Y;
            }

            Matrix <double> hull_matrix = DenseMatrix.OfArray(hull_array);

            List <double> edge_angles = Rotating_Caliper(hull_array);

            double?           min_area       = null;
            RectangleOriented best_rectangle = new RectangleOriented();

            /// Test each angle to find bounding box with smallest area
            foreach (double angle in edge_angles)
            {
                RectangleOriented rectangle = FindMinimumBoundingRectangle(hull_matrix, angle);


                double area = rectangle.Width * rectangle.Lenght;

                if (area < min_area || min_area == null)
                {
                    min_area       = area;
                    best_rectangle = rectangle;
                }
            }

            return(best_rectangle);
        }
예제 #3
0
        public static RectangleOriented FindMbrBoxByOverlap(List <PointD> list_of_points)
        {
            ConvexHullCreationResult <DefaultVertex2D> hull = ConvexHull.Create2D(list_of_points.Select(x => new double[2] {
                x.X, x.Y
            }).ToList());

            double[,] hull_array = new double[hull.Result.Count, 2];

            for (int i = 0; i < hull.Result.Count; i++)
            {
                hull_array[i, 0] = hull.Result[i].X;
                hull_array[i, 1] = hull.Result[i].Y;
            }

            Matrix <double> hull_matrix = DenseMatrix.OfArray(hull_array);

            List <double> edge_angles = Rotating_Caliper(hull_array);

            int?max_overlap = null;
            RectangleOriented best_rectangle = new RectangleOriented();

            /// Test each angle to find bounding box with smallest area
            foreach (double angle in edge_angles)
            {
                RectangleOriented rectangle = FindMinimumBoundingRectangle(hull_matrix, angle);


                int overlap = FindAllBorderPoints(list_of_points, rectangle, 0.05).Count;

                if (overlap > max_overlap || max_overlap == null)
                {
                    max_overlap    = overlap;
                    best_rectangle = rectangle;
                }
            }

            return(best_rectangle);
        }