Example #1
0
        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);
            }
        }
Example #2
0
 public void Triangle(TpplPoint a, TpplPoint b, TpplPoint c)
 {
     Clear();
     Points = new List <TpplPoint>(3)
     {
         a, b, c
     };
 }
Example #3
0
        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));
        }
Example #4
0
        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));
        }
Example #5
0
        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);
        }
Example #6
0
        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);
            }
        }
Example #7
0
            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);
                }
            }
Example #8
0
 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);
 }
Example #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]);
                }
            }
        }
Example #10
0
        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);
        }
Example #11
0
 public TpplPoly(TpplPoint a, TpplPoint b, TpplPoint c)
 {
     Triangle(a, b, c);
 }
Example #12
0
 public TpplPoint(TpplPoint src)
 {
     X  = src.X;
     Y  = src.Y;
     Id = src.Id;
 }