コード例 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="c1"></param>
 /// <param name="c2"></param>
 /// <param name="c3"></param>
 /// <returns>
 /// Whether the three coordinates are collinear
 /// and c2 lies between c1 and c3 inclusive.
 /// </returns>
 private bool IsBetween(ICoordinate c1, ICoordinate c2, ICoordinate c3)
 {
     if (CGAlgorithms.ComputeOrientation(c1, c2, c3) != 0)
     {
         return(false);
     }
     if (c1.X != c3.X)
     {
         if (c1.X <= c2.X && c2.X <= c3.X)
         {
             return(true);
         }
         if (c3.X <= c2.X && c2.X <= c1.X)
         {
             return(true);
         }
     }
     if (c1.Y != c3.Y)
     {
         if (c1.Y <= c2.Y && c2.Y <= c3.Y)
         {
             return(true);
         }
         if (c3.Y <= c2.Y && c2.Y <= c1.Y)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #2
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="o"></param>
            /// <param name="p"></param>
            /// <param name="q"></param>
            /// <returns></returns>
            private static int PolarCompare(ICoordinate o, ICoordinate p, ICoordinate q)
            {
                double dxp = p.X - o.X;
                double dyp = p.Y - o.Y;
                double dxq = q.X - o.X;
                double dyq = q.Y - o.Y;

                int orient = CGAlgorithms.ComputeOrientation(o, p, q);

                if (orient == CGAlgorithms.CounterClockwise)
                {
                    return(1);
                }
                if (orient == CGAlgorithms.Clockwise)
                {
                    return(-1);
                }

                // points are collinear - check distance
                double op = dxp * dxp + dyp * dyp;
                double oq = dxq * dxq + dyq * dyq;

                if (op < oq)
                {
                    return(-1);
                }
                if (op > oq)
                {
                    return(1);
                }
                return(0);
            }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        private Stack <ICoordinate> GrahamScan(ICoordinate[] c)
        {
            ICoordinate         p;
            Stack <ICoordinate> ps = new Stack <ICoordinate>(c.Length);

            ps.Push(c[0]);
            ps.Push(c[1]);
            ps.Push(c[2]);
            for (int i = 3; i < c.Length; i++)
            {
                p = ps.Pop();
                while (CGAlgorithms.ComputeOrientation(ps.Peek(), p, c[i]) > 0)
                {
                    p = ps.Pop();
                }
                ps.Push(p);
                ps.Push(c[i]);
            }
            ps.Push(c[0]);
            return(ps);
        }