Exemple #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 static bool IsBetween(Coordinate c1, Coordinate c2, Coordinate 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);
 }
Exemple #2
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="o"></param>
            /// <param name="p"></param>
            /// <param name="q"></param>
            /// <returns></returns>
            private static int PolarCompare(Coordinate o, Coordinate p, Coordinate 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.COUNTER_CLOCKWISE)
                {
                    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);
            }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        private static Stack <Coordinate> GrahamScan(Coordinate[] c)
        {
            Stack <Coordinate> ps = new Stack <Coordinate>(c.Length);

            ps.Push(c[0]);
            ps.Push(c[1]);
            ps.Push(c[2]);
            for (int i = 3; i < c.Length; i++)
            {
                Coordinate 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);
        }