Accord.Math.Geometry.PointsCloud.GetBoundingRectangle C# (CSharp) Method

GetBoundingRectangle() public static method

Get bounding rectangle of the specified list of points.
public static GetBoundingRectangle ( IEnumerable cloud, IntPoint &minXY, IntPoint &maxXY ) : void
cloud IEnumerable Collection of points to get bounding rectangle for.
minXY AForge.IntPoint Point comprised of smallest X and Y coordinates.
maxXY AForge.IntPoint Point comprised of biggest X and Y coordinates.
return void
        public static void GetBoundingRectangle( IEnumerable<IntPoint> cloud, out IntPoint minXY, out IntPoint maxXY )
        {
            int minX = int.MaxValue;
            int maxX = int.MinValue;
            int minY = int.MaxValue;
            int maxY = int.MinValue;

            foreach ( IntPoint pt in cloud )
            {
                int x = pt.X;
                int y = pt.Y;

                // check X coordinate
                if ( x < minX )
                    minX = x;
                if ( x > maxX )
                    maxX = x;

                // check Y coordinate
                if ( y < minY )
                    minY = y;
                if ( y > maxY )
                    maxY = y;
            }

            if ( minX > maxX ) // if no point appeared to set either minX or maxX
                throw new ArgumentException( "List of points can not be empty." );

            minXY = new IntPoint( minX, minY );
            maxXY = new IntPoint( maxX, maxY );
        }

Usage Example

Example #1
0
        /// <summary>
        /// Check if the specified set of points form a circle shape.
        /// </summary>
        ///
        /// <param name="edgePoints">Shape's points to check.</param>
        /// <param name="center">Receives circle's center on successful return.</param>
        /// <param name="radius">Receives circle's radius on successful return.</param>
        ///
        /// <returns>Returns <see langword="true"/> if the specified set of points form a
        /// circle shape or <see langword="false"/> otherwise.</returns>
        ///
        /// <remarks><para><note>Circle shape must contain at least 8 points to be recognized.
        /// The method returns <see langword="false"/> always, of number of points in the specified
        /// shape is less than 8.</note></para></remarks>
        ///
        public bool IsCircle(List <IntPoint> edgePoints, out Point center, out float radius)
        {
            // make sure we have at least 8 points for curcle shape
            if (edgePoints.Count < 8)
            {
                center = new Point(0, 0);
                radius = 0;
                return(false);
            }

            // get bounding rectangle of the points list
            IntPoint minXY, maxXY;

            PointsCloud.GetBoundingRectangle(edgePoints, out minXY, out maxXY);
            // get cloud's size
            IntPoint cloudSize = maxXY - minXY;

            // calculate center point
            center = minXY + (Point)cloudSize / 2;

            radius = ((float)cloudSize.X + cloudSize.Y) / 4;

            // calculate mean distance between provided edge points and estimated circle’s edge
            float meanDistance = 0;

            for (int i = 0, n = edgePoints.Count; i < n; i++)
            {
                meanDistance += (float)Math.Abs(center.DistanceTo(edgePoints[i]) - radius);
            }
            meanDistance /= edgePoints.Count;

            float maxDitance = Math.Max(minAcceptableDistortion,
                                        ((float)cloudSize.X + cloudSize.Y) / 2 * relativeDistortionLimit);

            return(meanDistance <= maxDitance);
        }
All Usage Examples Of Accord.Math.Geometry.PointsCloud::GetBoundingRectangle