Пример #1
0
        //Build Convex Hull using Graham Scan
        private static Stack <Point> Build(List <Point> arr)
        {
            Point         firstPoint = new Point(arr[0].X, arr[0].Y);
            Stack <Point> hullStack  = new Stack <Point>();

            hullStack.Push(arr[0]);
            hullStack.Push(arr[1]);
            Point top       = arr[1];
            Point nextToTop = arr[0];

            for (int i = 2; i < arr.Count; i++)
            {
                while ((ActionsWithVectors.VectorProduct(ActionsWithVectors.SubtractOf(arr[i], nextToTop),
                                                         ActionsWithVectors.SubtractOf(top, nextToTop)) <= 0) && (!Equals(top, firstPoint)))
                {
                    top = nextToTop;
                    hullStack.Pop();
                    hullStack.Pop();
                    if (Equals(top, firstPoint))
                    {
                        nextToTop = top;
                    }
                    else
                    {
                        nextToTop = hullStack.Peek();
                    }
                    hullStack.Push(top);
                }
                hullStack.Push(arr[i]);
                nextToTop = top;
                top       = arr[i];
            }
            return(hullStack);
        }
Пример #2
0
        public int Compare(Point v1, Point v2)
        {
            int result = 1;

            if ((ActionsWithVectors.VectorProduct(ActionsWithVectors.SubtractOf(v1, FirstPoint), ActionsWithVectors.SubtractOf(v2, FirstPoint)) < 0) ||
                (ActionsWithVectors.VectorProduct(ActionsWithVectors.SubtractOf(v1, FirstPoint), ActionsWithVectors.SubtractOf(v2, FirstPoint)) == 0) &&
                (ActionsWithVectors.Distance(v1, FirstPoint) < ActionsWithVectors.Distance(v2, FirstPoint)))
            {
                result = -1;
            }
            if ((v1.X == v2.X) && (v1.Y == v2.Y))
            {
                result = 0;
            }
            return(result);
        }
Пример #3
0
        public static bool[,] GetFieldFilling(int rows, int columns, List <Point> Minutiae)
        {
            bool[,] Field = new bool[rows, columns];
            List <Point> Hull = ConvexHull.GetConvexHull(Minutiae);

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    Point CurPoint  = new Point(i, j);
                    bool  GoodPoint = true;
                    for (int k = Hull.Count - 1; (k > 0) && GoodPoint; k--)
                    {
                        if (ActionsWithVectors.VectorProduct(ActionsWithVectors.SubtractOf(Hull[k - 1], Hull[k]),
                                                             ActionsWithVectors.SubtractOf(CurPoint, Hull[k])) > 0)
                        {
                            GoodPoint = false;
                        }
                    }
                    if (GoodPoint)
                    {
                        if (ActionsWithVectors.VectorProduct(ActionsWithVectors.SubtractOf(Hull[Hull.Count - 1], Hull[0]),
                                                             ActionsWithVectors.SubtractOf(CurPoint, Hull[0])) > 0)
                        {
                            GoodPoint = false;
                        }
                    }
                    if (GoodPoint)
                    {
                        Field[i, j] = true;
                    }
                    else
                    {
                        Field[i, j] = false;
                    }
                }
            }
            return(Field);
        }