Exemplo n.º 1
0
        /**
         * Add the intersections of triangle t with the section to the list of
         * intersection (set)
         */
        void cut(Triangle_dt t)
        {
            if (t.isHalfplane())
            {
                return;
            }
            Point_dt p1 = t.p1(), p2 = t.p2(), p3 = t.p3();
            int      f1 = p1.pointLineTest(_p1, _p2);
            int      f2 = p2.pointLineTest(_p1, _p2);
            int      f3 = p3.pointLineTest(_p1, _p2);

            if ((f1 == Point_dt.LEFT | f1 == Point_dt.RIGHT) &&
                (f1 == f2 && f1 == f3))
            {
                return;
            }
            if (f1 != f2 && _p1.pointLineTest(p1, p2) != _p2.pointLineTest(p1, p2))
            {
                Add(intersection(p1, p2));
            }
            if (f2 != f3 && _p1.pointLineTest(p2, p3) != _p2.pointLineTest(p2, p3))
            {
                Add(intersection(p2, p3));
            }
            if (f3 != f1 && _p1.pointLineTest(p3, p1) != _p2.pointLineTest(p3, p1))
            {
                Add(intersection(p3, p1));
            }
        }
Exemplo n.º 2
0
        /** return true iff the segment _p1,_p2 is cutting t */
        bool cut(Point_dt pp1, Point_dt pp2, Triangle_dt t)
        {
            bool ans = false;

            if (t.isHalfplane())
            {
                return(false);
            }
            Point_dt p1 = t.p1(), p2 = t.p2(), p3 = t.p3();
            int      f1 = p1.pointLineTest(pp1, pp2);
            int      f2 = p2.pointLineTest(pp1, pp2);
            int      f3 = p3.pointLineTest(pp1, pp2);

            if ((f1 == Point_dt.LEFT | f1 == Point_dt.RIGHT) &&
                (f1 == f2 && f1 == f3))
            {
                return(false);
            }

            if (f1 != f2 && pp1.pointLineTest(p1, p2) != pp2.pointLineTest(p1, p2))
            {
                return(true);
            }
            if (f2 != f3 && pp1.pointLineTest(p2, p3) != pp2.pointLineTest(p2, p3))
            {
                return(true);
            }
            if (f3 != f1 && pp1.pointLineTest(p3, p1) != pp2.pointLineTest(p3, p1))
            {
                return(true);
            }

            return(ans);
        }
Exemplo n.º 3
0
 //public int _id;
 /** constructs a triangle form 3 point - store it in counterclockwised order.*/
 public Triangle_dt(Point_dt A, Point_dt B, Point_dt C)
 {
     //visitflag=visitValue;
     a = A;
     int res = C.pointLineTest(A,B);
     if ( (res <= Point_dt.LEFT) ||
          (res == Point_dt.INFRONTOFA) ||
          (res == Point_dt.BEHINDB) )
     {
         b = B;
         c = C;
     }
     else
     {  // RIGHT
         Console.WriteLine("Warning, ajTriangle(A,B,C) "+  "expects points in counterclockwise order.");
         Console.WriteLine("" + A + B + C);
         b=C;
         c=B;
     }
     circumcircle();
     //_id = _counter++;
     //_counter++;_c2++;
     //if(_counter%10000 ==0) System.out.println("Triangle: "+_counter);
 }
Exemplo n.º 4
0
Arquivo: DT.cs Projeto: adiel2012/jdt
 private Triangle_dt treatDegeneracyInside(Triangle_dt t, Point_dt p)
 {
     if (t.abnext.halfplane
             && p.pointLineTest(t.b, t.a) == Point_dt.ONSEGMENT)
         return extendOutside(t.abnext, p);
     if (t.bcnext.halfplane
             && p.pointLineTest(t.c, t.b) == Point_dt.ONSEGMENT)
         return extendOutside(t.bcnext, p);
     if (t.canext.halfplane
             && p.pointLineTest(t.a, t.c) == Point_dt.ONSEGMENT)
         return extendOutside(t.canext, p);
     return null;
 }
Exemplo n.º 5
0
Arquivo: DT.cs Projeto: adiel2012/jdt
        private Triangle_dt insertPointSimple(Point_dt p)
        {
            nPoints++;
            if (!allCollinear)
            {
                Triangle_dt t = find(startTriangle, p);
                if (t.halfplane)
                    startTriangle = extendOutside(t, p);
                else
                    startTriangle = extendInside(t, p);
                return startTriangle;
            }

            if (nPoints == 1)
            {
                firstP = p;
                return null;
            }

            if (nPoints == 2)
            {
                startTriangulation(firstP, p);
                return null;
            }

            switch (p.pointLineTest(firstP, lastP))
            {
                case Point_dt.LEFT:
                    startTriangle = extendOutside(firstT.abnext, p);
                    allCollinear = false;
                    break;
                case Point_dt.RIGHT:
                    startTriangle = extendOutside(firstT, p);
                    allCollinear = false;
                    break;
                case Point_dt.ONSEGMENT:
                    insertCollinear(p, Point_dt.ONSEGMENT);
                    break;
                case Point_dt.INFRONTOFA:
                    insertCollinear(p, Point_dt.INFRONTOFA);
                    break;
                case Point_dt.BEHINDB:
                    insertCollinear(p, Point_dt.BEHINDB);
                    break;
            }
            return null;
        }
Exemplo n.º 6
0
Arquivo: DT.cs Projeto: adiel2012/jdt
 private Triangle_dt extendOutside(Triangle_dt t, Point_dt p)
 {
     if (p.pointLineTest(t.a, t.b) == Point_dt.ONSEGMENT)
     {
         Triangle_dt dg = new Triangle_dt(t.a, t.b, p);
         Triangle_dt hp = new Triangle_dt(p, t.b);
         t.b = p;
         dg.abnext = t.abnext;
         dg.abnext.switchneighbors(t, dg);
         dg.bcnext = hp;
         hp.abnext = dg;
         dg.canext = t;
         t.abnext = dg;
         hp.bcnext = t.bcnext;
         hp.bcnext.canext = hp;
         hp.canext = t;
         t.bcnext = hp;
         return dg;
     }
     Triangle_dt ccT = extendcounterclock(t, p);
     Triangle_dt cT = extendclock(t, p);
     ccT.bcnext = cT;
     cT.canext = ccT;
     startTriangleHull = cT;
     return cT.abnext;
 }
Exemplo n.º 7
0
Arquivo: DT.cs Projeto: adiel2012/jdt
        private Triangle_dt extendcounterclock(Triangle_dt t, Point_dt p)
        {
            t.halfplane = false;
            t.c = p;
            t.circumcircle();

            Triangle_dt tca = t.canext;

            if (p.pointLineTest(tca.a, tca.b) >= Point_dt.RIGHT)
            {
                Triangle_dt nT = new Triangle_dt(t.a, p);
                nT.abnext = t;
                t.canext = nT;
                nT.canext = tca;
                tca.bcnext = nT;
                return nT;
            }
            return extendcounterclock(tca, p);
        }
Exemplo n.º 8
0
Arquivo: DT.cs Projeto: adiel2012/jdt
        private Triangle_dt extendclock(Triangle_dt t, Point_dt p)
        {
            t.halfplane = false;
            t.c = p;
            t.circumcircle();

            Triangle_dt tbc = t.bcnext;

            if (p.pointLineTest(tbc.a, tbc.b) >= Point_dt.RIGHT)
            {
                Triangle_dt nT = new Triangle_dt(p, t.b);
                nT.abnext = t;
                t.bcnext = nT;
                nT.bcnext = tbc;
                tbc.canext = nT;
                return nT;
            }
            return extendclock(tbc, p);
        }
Exemplo n.º 9
0
Arquivo: DT.cs Projeto: adiel2012/jdt
 /*
  * assumes v is NOT an halfplane!
  * returns the next triangle for find.
  */
 private static Triangle_dt findnext1(Point_dt p, Triangle_dt v)
 {
     if (p.pointLineTest(v.a, v.b) == Point_dt.RIGHT && !v.abnext.halfplane)
         return v.abnext;
     if (p.pointLineTest(v.b, v.c) == Point_dt.RIGHT && !v.bcnext.halfplane)
         return v.bcnext;
     if (p.pointLineTest(v.c, v.a) == Point_dt.RIGHT && !v.canext.halfplane)
         return v.canext;
     if (p.pointLineTest(v.a, v.b) == Point_dt.RIGHT)
         return v.abnext;
     if (p.pointLineTest(v.b, v.c) == Point_dt.RIGHT)
         return v.bcnext;
     if (p.pointLineTest(v.c, v.a) == Point_dt.RIGHT)
         return v.canext;
     return null;
 }
Exemplo n.º 10
0
        /**
         * determinates if this triangle contains the point p.
         * @param p the query point
         * @return true iff p is not null and is inside this triangle (Note: on boundary is considered inside!!).
         */
        public bool contains(Point_dt p)
        {
            bool ans = false;
            if (this.halfplane || p == null) return false;

            if ((p.x == a.x && p.y == a.y) || (p.x == b.x && p.y == b.y) || (p.x == c.x && p.y == c.y)) return true;
            int a12 = p.pointLineTest(a, b);
            int a23 = p.pointLineTest(b, c);
            int a31 = p.pointLineTest(c, a);

            if ((a12 == Point_dt.LEFT && a23 == Point_dt.LEFT && a31 == Point_dt.LEFT) ||
            (a12 == Point_dt.RIGHT && a23 == Point_dt.RIGHT && a31 == Point_dt.RIGHT) ||
            (a12 == Point_dt.ONSEGMENT || a23 == Point_dt.ONSEGMENT || a31 == Point_dt.ONSEGMENT))
                ans = true;

            return ans;
        }
Exemplo n.º 11
0
        /** return true iff the segment _p1,_p2 is cutting t */
        bool cut(Point_dt pp1, Point_dt pp2, Triangle_dt t)
        {
            bool ans = false;
            if (t.isHalfplane())
                return false;
            Point_dt p1 = t.p1(), p2 = t.p2(), p3 = t.p3();
            int f1 = p1.pointLineTest(pp1, pp2);
            int f2 = p2.pointLineTest(pp1, pp2);
            int f3 = p3.pointLineTest(pp1, pp2);

            if ((f1 == Point_dt.LEFT | f1 == Point_dt.RIGHT)
                    && (f1 == f2 && f1 == f3))
                return false;

            if (f1 != f2 && pp1.pointLineTest(p1, p2) != pp2.pointLineTest(p1, p2))
                return true;
            if (f2 != f3 && pp1.pointLineTest(p2, p3) != pp2.pointLineTest(p2, p3))
                return true;
            if (f3 != f1 && pp1.pointLineTest(p3, p1) != pp2.pointLineTest(p3, p1))
                return true;

            return ans;
        }