protected bool InCone(TPPLPoint p1, TPPLPoint p2, TPPLPoint p3, TPPLPoint p)
        {
            bool convex;

            convex = IsConvex(p1, p2, p3);

            if (convex)
            {
                if (!IsConvex(p1, p2, p))
                {
                    return(false);
                }
                if (!IsConvex(p2, p3, p))
                {
                    return(false);
                }
                return(true);
            }
            else
            {
                if (IsConvex(p1, p2, p))
                {
                    return(true);
                }
                if (IsConvex(p2, p3, p))
                {
                    return(true);
                }
                return(false);
            }
        }
Exemple #2
0
 public void Triangle(TPPLPoint a, TPPLPoint b, TPPLPoint c)
 {
     Clear();
     Points = new List <TPPLPoint>(3)
     {
         a, b, c
     };
 }
        protected tppl_float Distance(TPPLPoint p1, TPPLPoint p2)
        {
            tppl_float dx, dy;

            dx = p2.X - p1.X;
            dy = p2.Y - p1.Y;

            return((tppl_float)Math.Sqrt(dx * dx + dy * dy));
        }
        protected bool InCone(PartitionVertex v, TPPLPoint p)
        {
            TPPLPoint p1, p2, p3;

            p1 = v.previous.p;
            p2 = v.p;
            p3 = v.next.p;

            return(InCone(p1, p2, p3, p));
        }
Exemple #5
0
        public TPPLPoly(int numPoints)
        {
            Clear();

            Points = new List <TPPLPoint>(numPoints);

            for (int i = 0; i < numPoints; i++)
            {
                Points[i] = new TPPLPoint();
            }
        }
        protected int Intersects(TPPLPoint p11, TPPLPoint p12, TPPLPoint p21, TPPLPoint p22)
        {
            if ((p11.X == p21.X) && (p11.Y == p21.Y))
            {
                return(0);
            }
            if ((p11.X == p22.X) && (p11.Y == p22.Y))
            {
                return(0);
            }
            if ((p12.X == p21.X) && (p12.Y == p21.Y))
            {
                return(0);
            }
            if ((p12.X == p22.X) && (p12.Y == p22.Y))
            {
                return(0);
            }

            TPPLPoint v1ort = new TPPLPoint(),
                      v2ort = new TPPLPoint(),
                      v     = new TPPLPoint();

            tppl_float dot11, dot12, dot21, dot22;

            v1ort.X = p12.Y - p11.Y;
            v1ort.Y = p11.X - p12.X;

            v2ort.X = p22.Y - p21.Y;
            v2ort.Y = p21.X - p22.X;

            v     = p21 - p11;
            dot21 = v.X * v1ort.X + v.Y * v1ort.Y;
            v     = p22 - p11;
            dot22 = v.X * v1ort.X + v.Y * v1ort.Y;

            v     = p11 - p21;
            dot11 = v.X * v2ort.X + v.Y * v2ort.Y;
            v     = p12 - p21;
            dot12 = v.X * v2ort.X + v.Y * v2ort.Y;

            if (dot11 * dot12 > 0)
            {
                return(0);
            }
            if (dot21 * dot22 > 0)
            {
                return(0);
            }

            return(1);
        }
        protected bool IsReflex(TPPLPoint p1, TPPLPoint p2, TPPLPoint p3)
        {
            tppl_float tmp;

            tmp = (p3.Y - p1.Y) * (p2.X - p1.X) - (p3.X - p1.X) * (p2.Y - p1.Y);

            if (tmp < 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
            public static bool IsConvex(TPPLPoint p1, TPPLPoint p2, TPPLPoint p3)
            {
                tppl_float tmp;

                tmp = (p3.Y - p1.Y) * (p2.X - p1.X) - (p3.X - p1.X) * (p2.Y - p1.Y);

                if (tmp > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
Exemple #9
0
        public TPPLPoly(TPPLPoly src)
        {
            Clear();

            Hole = src.Hole;

            if (src.Points != null)
            {
                Points = new List <TPPLPoint>(src.Points.Count);

                for (int i = 0; i < Points.Count; i++)
                {
                    Points[i] = new TPPLPoint(src.Points[i]);
                }
            }
        }
 protected bool IsInside(TPPLPoint p1, TPPLPoint p2, TPPLPoint p3, TPPLPoint p)
 {
     if (IsConvex(p1, p, p2))
     {
         return(false);
     }
     if (IsConvex(p2, p, p3))
     {
         return(false);
     }
     if (IsConvex(p3, p, p1))
     {
         return(false);
     }
     return(true);
 }
        TPPLPoint Normalize(TPPLPoint p)
        {
            TPPLPoint  r = new TPPLPoint();
            tppl_float n = (tppl_float)Math.Sqrt(p.X * p.X + p.Y * p.Y);

            if (n != (tppl_float)0)
            {
                r = p / n;
            }
            else
            {
                r.X = 0;
                r.Y = 0;
            }

            return(r);
        }
Exemple #12
0
 public TPPLPoly(TPPLPoint a, TPPLPoint b, TPPLPoint c)
 {
     Triangle(a, b, c);
 }
Exemple #13
0
 public TPPLPoint(TPPLPoint src)
 {
     X  = src.X;
     Y  = src.Y;
     Id = src.Id;
 }