예제 #1
0
        public void DrawDots(System.Drawing.Graphics gContext, int w, int h)
        {
            cVertexList listcopy = new cVertexList();

            listcopy.SetVertex(list.head.Point.X, list.head.Point.Y);

            if (nlinks == 3)
            {
                /*for the first link:*/
                listcopy = MakePoints(0, firstlinks, firstlinks - 1, list.head, list.head.NextVertex, listcopy);
                /*set the middle link*/
                listcopy.SetVertex(list.head.NextVertex.Point.X, list.head.NextVertex.Point.Y);
                listcopy.SetVertex(list.head.NextVertex.NextVertex.Point.X, list.head.NextVertex.NextVertex.Point.Y);
                /* for the last link, the third one*/
                listcopy = MakePoints(firstlinks + 1, nlinksback, nlinksback, list.head.NextVertex.NextVertex, list.head.PrevVertex, listcopy);
            }

            else
            {
                if (nlinksback > 2)
                /*if we have any extra - points*/
                {
                    /*first link:*/
                    listcopy = MakePoints(0, firstlinks, firstlinks - 1, list.head, list.head.NextVertex, listcopy);
                    /*set the middle point:*/
                    listcopy.SetVertex(list.head.NextVertex.Point.X, list.head.NextVertex.Point.Y);
                    /*set the last link*/
                    listcopy = MakePoints(firstlinks, nlinksback + 1, nlinksback - 1, list.head.PrevVertex.PrevVertex, list.head.PrevVertex, listcopy);
                } //end if nlinksback > 2
            }     // end else
            /*set the last point and draw everything*/
            listcopy.SetVertex(list.head.PrevVertex.Point.X, list.head.PrevVertex.Point.Y);
            listcopy.DrawPoints(gContext, w, h);
        }
예제 #2
0
        public DelaunayTri_Old(List <Vector3d> myListVectors)
            : this()
        {
            cVertexList mycList = InitData(myListVectors);

            Start(mycList);
        }
예제 #3
0
 public void ClearChain()
 /*for cleaning the chain after each edit operation*/
 {
     nlinksback = 0;
     firstlinks = 0;
     listcopy   = new cVertexList();
 }
예제 #4
0
        private void Sort(cVertexList a, int lo0, int hi0)
        {
            if (lo0 >= hi0)
            {
                return;
            }
            cVertex mid = new cVertex();

            mid = a.GetElement(hi0);
            int lo = lo0;
            int hi = hi0 - 1;

            while (lo <= hi)
            {
                while (lo <= hi && ((Compare(a.GetElement(lo), mid) == 1) || (Compare(a.GetElement(lo), mid) == 0)))
                {
                    lo++;
                }

                while (lo <= hi && ((Compare(a.GetElement(hi), mid) == -1) || (Compare(a.GetElement(hi), mid) == 0)))
                {
                    hi--;
                }

                if (lo < hi)
                {
                    Swap(a.GetElement(lo), a.GetElement(hi));
                }
            }
            Swap(a.GetElement(lo), a.GetElement(hi0));
            Sort(a, lo0, lo - 1);
            Sort(a, lo + 1, hi0);
        }
예제 #5
0
 public bool Start(cVertexList p, cVertexList q)
 {
     p0.X = p0.Y = 0;
     if (!CheckForConvexity(p, q))
     {
         System.Diagnostics.Debug.WriteLine("Second polygon is  not convex...");
         return(false);
     }
     else
     {
         B = new cVertexList();
         q.ListCopy(B);
         n = p.n;
         s = q.n;
         m = n + m;
         P = new cVertexList();
         cVertex v = p.head;
         do
         {
             cVertex t = new cVertex(v.Point.X, v.Point.Y);
             P.InsertBeforeHead(t);
             v = v.NextVertex;
         } while (v != p.head);
         j0     = ReadVertices();
         output = new cVertexList();
     }
     Vectorize();
     System.Diagnostics.Debug.WriteLine("Before sorting ...");
     PrintPoints();
     Qsort();
     System.Diagnostics.Debug.WriteLine("After sorting ... ");
     PrintPoints();
     Convolve();
     return(true);
 }
예제 #6
0
        private void Pop(cVertexList top)
        {
            //simulating a stack behavior for cVertexList list
            //Pop procedure
            cVertex last = new cVertex();

            //last=top0.head.prev;
            top.Delete(top.head.PrevVertex);
        }
        private bool diagdrawn = true;     //diag-s've been drawn after triang?

        public cPolygoni(cVertexList list)
        {
            this.list = list;
            listcopy  = new cVertexList();
            diaglist  = new cDiagonalList();
            CG        = new cPointd(0, 0);
            intCount  = 0;
            diagdrawn = true;
        }
예제 #8
0
        private bool CheckForConvexity(cVertexList A, cVertexList B)
        {
            if (A.Ccw() != 1)
                A.ReverseList();
            if (B.Ccw() != 1)
                B.ReverseList();

            if (!B.CheckForConvexity())  /* Second polygon must be convex */
                return false;

            B.ReverseList();

            return true;
        }
예제 #9
0
        /*---------------------------------------------------------------------
        *  Performs the Graham scan on an array of angularly sorted points P.
        *  ---------------------------------------------------------------------*/

        private cVertexList Graham()
        {
            cVertexList top;
            int         i;

            //  cVertex p1, p2;  /* Top two points on stack. */


            /* Initialize stack. */
            top = new cVertexList();
            cVertex v1 = new cVertex(list.head.Point.X, list.head.Point.Y);

            v1.IndexInModel = list.head.IndexInModel;
            v1.IsProcessed  = list.head.IsProcessed;

            cVertex v2 = new cVertex(list.head.NextVertex.Point.X, list.head.NextVertex.Point.Y);

            v2.IndexInModel = list.head.NextVertex.IndexInModel;
            v2.IsProcessed  = list.head.NextVertex.IsProcessed;


            Push(v1, top);
            Push(v2, top);

            // Bottom two elements will never be removed.
            i = 2;

            while (i < list.n)
            {
                cVertex v3 = new cVertex(list.GetElement(i).Point.X, list.GetElement(i).Point.Y);
                v3.IsProcessed  = list.GetElement(i).IsProcessed;
                v3.IndexInModel = list.GetElement(i).IndexInModel;

                if (v1.Point.Left(top.head.PrevVertex.Point, top.head.PrevVertex.PrevVertex.Point, v3.Point))
                {
                    Push(v3, top);
                    i++;
                }
                else
                {
                    if (top.n > 2)
                    {
                        Pop(top);
                    }
                }
            }

            return(top);
        }
예제 #10
0
        private cVertexList InitData(List <Vector3d> myListVectors)
        {
            //this.list = list;
            Edges = new cEdgeList();
            Faces = new cFaceList();

            cVertexList mycList = new cVertexList();

            for (int i = 0; i < myListVectors.Count; i++)
            {
                Vector3d v = myListVectors[i];
                mycList.SetVertex3D(v.X, v.Y, v.Z);
            }
            return(mycList);
        }
예제 #11
0
 public void Start(cVertexList myList)
 {
     this.Vertices = new cVertexList();
     myList.ListCopy(this.Vertices);
     ReadVertices();
     if (DoubleTriangle())
     {
         ConstructHull();
         LowerFaces();
         Print();
     }
     else
     {
         throw new Exception("Delaunay Failed");
     }
 }
예제 #12
0
 public void Start(cVertexList myList)
 {
     this.Vertices = new cVertexList();
     myList.ListCopy(this.Vertices);
     ReadVertices();
     if (doubleTriangle())
     {
         ConstructHull();
         LowerFaces();
         Print();
     }
     else
     {
         System.Windows.Forms.MessageBox.Show("Delaunay Failed");
     }
 }
예제 #13
0
        /*Makes a copy of present list
         */
        public void ListCopy(cVertexList list)
        {
            cVertex temp1 = head, temp2;

            do
            {
                temp2              = new cVertex(); // Create a new vertex cell
                temp2.Point        = temp1.Point;   // Fill it with the same cPointi as in list
                temp2.IsProcessed  = temp1.IsProcessed;
                temp2.IsEar        = temp1.IsEar;
                temp2.Edge         = temp1.Edge;
                temp2.IsOnHull     = temp1.IsOnHull;
                temp2.IndexInModel = temp1.IndexInModel;
                list.InsertBeforeHead(temp2);
                temp1 = temp1.NextVertex;
            } while (temp1 != head);
        }
예제 #14
0
        /* Reverses the pointCloud, in order to get a ccw orientation
         * 1234 becomes 1432
         */
        public void ReverseList()
        {
            cVertexList listcopy = new cVertexList();
            cVertex     temp1, temp2;

            ListCopy(listcopy);
            this.ClearVertexList();

            //Fill this list in proper order:
            temp1 = listcopy.head;
            do
            {
                temp2       = new cVertex();
                temp2.Point = temp1.Point;
                InsertBeforeHead(temp2);
                temp1 = temp1.PrevVertex;
            } while (temp1 != listcopy.head);
            System.Diagnostics.Debug.WriteLine("Reversing list...");
        }
예제 #15
0
        public void Voronoi(List <Vector3d> myListVectors)
        {
            cVertexList mycList = InitData(myListVectors);

            Start(mycList);

            for (int i = 0; i < this.Faces.ListFaces.Count; i++)
            {
                cFace face = this.Faces.ListFaces[i];
                for (int j = 0; j < face.Edges.Length; j++)
                {
                    cEdge edge = face.Edges[j];
                    for (int k = 0; k < edge.Adjface.Length; k++)
                    {
                        cFace adjFace = edge.Adjface[k];
                        cEdge newEdge = new cEdge();

                        //Kante m durch Verbindung der Umkreismittelpunkte von k und k+1
                    }
                }
            }

            //var t = DelaunayTriangulation<TCell>.Create(data);
            //var myCells = t.Cells;
            //var edges = new HashSet<TEdge>(new EdgeComparer());

            //foreach (var c in myCells)
            //{
            //    for (int i = 0; i < c.Adjacency.Length; i++)
            //    {
            //        var af = c.Adjacency[i];
            //        if (af != null)
            //            edges.Add(new TEdge { Source = c, Target = af });
            //    }
            //}

            //return new VoronoiMesh<TCell, TEdge>
            //{
            //    Cells = myCells,
            //    Edges = edges.ToList()
            //};
        }
예제 #16
0
        private bool CheckForConvexity(cVertexList A, cVertexList B)
        {
            if (A.Ccw() != 1)
            {
                A.ReverseList();
            }
            if (B.Ccw() != 1)
            {
                B.ReverseList();
            }

            if (!B.CheckForConvexity())  /* Second polygon must be convex */
            {
                return(false);
            }

            B.ReverseList();

            return(true);
        }
예제 #17
0
        /* Makes the last element to be the head and head to be the last,
         * e.g., 0123 becomes 3210
         */
        public void ReverseListCompletely()
        {
            cVertexList listcopy = new cVertexList();
            cVertex     temp1, temp2;

            ListCopy(listcopy);
            this.ClearVertexList();

            //Fill this list in proper order:
            temp1 = listcopy.head.PrevVertex;
            do
            {
                temp2              = new cVertex();
                temp2.Point        = temp1.Point;
                temp2.IsProcessed  = temp1.IsProcessed;
                temp2.IndexInModel = temp1.IndexInModel;
                InsertBeforeHead(temp2);
                temp1 = temp1.PrevVertex;
            } while (temp1 != listcopy.head.PrevVertex);
            System.Diagnostics.Debug.WriteLine("Reversing list completely...");
        }
예제 #18
0
 /* Equivalent of main() function in the C code,
  * returns false if polygons are not convex
  */
 public bool Start(cVertexList p, cVertexList q)
 {
     intersection = true;
     this.P       = new cVertexList();
     this.Q       = new cVertexList();
     p.ListCopy(P);
     q.ListCopy(Q);
     if (!CheckForConvexity())
     {
         System.Diagnostics.Debug.WriteLine("Polygons are not convex...");
         return(false);
     }
     else
     {
         System.Diagnostics.Debug.WriteLine("Polygons are convex...");
         n      = P.n;
         m      = Q.n;
         inters = new cVertexList();
         ConvexIntersect(P, Q, n, m);
     }
     return(true);
 }
예제 #19
0
        }//end TwoCircles00

        /*Method used for cretaing the "extra-points" that will be displayed
         * on the screen after the arm is straightened. Called from DrawPoints */

        public cVertexList MakePoints(int lo, int hi1, int hi2, cVertex first, cVertex last, cVertexList listcopy)
        {
            double xaux;                    //auxiliary variable for storin the info
            double lenaux = 0;              //auxiliary variable for storing the Length of the
            //current link
            cPointi v1 = new cPointi(0, 0); //aux variable for computing the values
            //of the new points
            double sum = 0;                 //the sum of the previous link Lengths

            for (i = lo; i < hi1; i++)
            {
                lenaux += linklenback[i];
            }
            sum = 0;

            for (i = lo; i < hi2; i++)
            {
                sum += linklenback[i];
                xaux = sum / (double)lenaux;
                v1.X = (int)(.5 + (1 - xaux) * first.Point.X + xaux * last.Point.X);
                v1.Y = (int)(.5 + (1 - xaux) * first.Point.Y + xaux * last.Point.Y);
                listcopy.SetVertex(v1.X, v1.Y);
            }//end for

            return(listcopy);
        }
예제 #20
0
 private void Push(cVertex p, cVertexList top)
 {
     //simulating a stack behavior for cVertexList list
     //Push procedure
     top.InsertBeforeHead(p);
 }
예제 #21
0
        char code         = '0';             /* intersection code returned by SegSegInt*/

        public cSegSeg(cVertexList list)
        {
            p         = new cPointd(0, 0);
            this.list = list;
        }
예제 #22
0
 public ConvexHull3D()
 {
     Vertices = new cVertexList();
     Edges    = new cEdgeList();
     Faces    = new cFaceList();
 }
예제 #23
0
 private void qsort(cVertexList a)
 {
     Sort(a, 1, a.n - 1);
 }
예제 #24
0
        /*intersection is used for determining the number of intersections of the
         * two circles: 0 for point out of reach, 1 for two tangent circles,
         * 2 for 2 intersections, 3 for identical circles. */

        /*constructor*/
        public cChain(cVertexList list)
        {
            this.list = list;
        }
예제 #25
0
        /*---------------------------------------------------------------------
        * Consult the book for explanations
        *--------------------------------------------------------------------*/
        private void ConvexIntersect(cVertexList P, cVertexList Q, int n, int m)
        /* P has n pointCloud, Q has m pointCloud. */
        {
            /* Initialize variables. */
            a          = new cVertex();
            b          = new cVertex();
            a          = P.head; b = Q.head;
            aa         = ba = 0;
            Origin     = new cPointi(); /* (0,0) */
            inflag     = new cInFlag();
            FirstPoint = true;
            cVertex a1, b1;

            A  = new cPointi();
            B  = new cPointi();
            p  = new cPointd();
            q  = new cPointd();
            p0 = new cPointd();

            do
            {
                /* System.Diagnostics.Debug.WriteLine("Before Advances:a="+a.v.x+","+a.v.y+
                 * ", b="+b.v.x+","+b.v.y+"; aa="+aa+", ba="+ba+"; inflag="+
                 * inflag.f); */
                /* Computations of key variables. */
                a1 = a.PrevVertex;
                b1 = b.PrevVertex;

                SubVec(a.Point, a1.Point, A);
                SubVec(b.Point, b1.Point, B);

                cross = Origin.TriangleSign(Origin, A, B);
                aHB   = b1.Point.TriangleSign(b1.Point, b.Point, a.Point);
                bHA   = a1.Point.TriangleSign(a1.Point, a.Point, b.Point);
                System.Diagnostics.Debug.WriteLine("cross=" + cross + ", aHB=" + aHB + ", bHA=" + bHA);

                /* If A & B intersect, update inflag. */
                code = a1.Point.SegSegInt(a1.Point, a.Point, b1.Point, b.Point, p, q);
                System.Diagnostics.Debug.WriteLine("SegSegInt: code = " + code);

                if (code == '1' || code == 'v')
                {
                    if (inflag.f == cInFlag.Unknown && FirstPoint)
                    {
                        aa         = ba = 0;
                        FirstPoint = false;
                        p0.x       = p.x; p0.y = p.y;
                        InsertInters(p0.x, p0.y);
                    }
                    inflag = InOut(p, inflag, aHB, bHA);
                    System.Diagnostics.Debug.WriteLine("InOut sets inflag=" + inflag.f);
                }

                /*-----Advance rules-----*/

                /* Special case: A & B overlap and oppositely oriented. */
                if ((code == 'e') && (Dot(A, B) < 0))
                {
                    InsertSharedSeg(p, q);
                    return;
                }

                /* Special case: A & B parallel and separated. */
                if ((cross == 0) && (aHB < 0) && (bHA < 0))
                {
                    System.Diagnostics.Debug.WriteLine("P and Q are disjoint.");
                    return;
                }


                /* Special case: A & B collinear. */
                else if ((cross == 0) && (aHB == 0) && (bHA == 0))
                {
                    /* Advance but do not output point. */
                    if (inflag.f == cInFlag.Pin)
                    {
                        b = Advance(b, "ba", inflag.f == cInFlag.Qin, b.Point);
                    }
                    else
                    {
                        a = Advance(a, "aa", inflag.f == cInFlag.Pin, a.Point);
                    }
                }

                /* Generic cases. */
                else if (cross >= 0)
                {
                    if (bHA > 0)
                    {
                        a = Advance(a, "aa", inflag.f == cInFlag.Pin, a.Point);
                    }
                    else
                    {
                        b = Advance(b, "ba", inflag.f == cInFlag.Qin, b.Point);
                    }
                }
                else /* if ( cross < 0 ) */
                {
                    if (aHB > 0)
                    {
                        b = Advance(b, "ba", inflag.f == cInFlag.Qin, b.Point);
                    }
                    else
                    {
                        a = Advance(a, "aa", inflag.f == cInFlag.Pin, a.Point);
                    }
                }
                System.Diagnostics.Debug.WriteLine("After advances:a=(" + a.Point.X + ", " + a.Point.Y +
                                                   "), b=(" + b.Point.X + ", " + b.Point.Y + "); aa=" + aa +
                                                   ", ba=" + ba + "; inflag=" + inflag.f);

                /* Quit when both adv. indices have cycled, or one has cycled twice. */
            } while (((aa < n) || (ba < m)) && (aa < 2 * n) && (ba < 2 * m));

            if (!FirstPoint) /* If at least one point output, close up. */
            {
                InsertInters(p0.x, p0.y);
            }

            /* Deal with special cases: not implemented. */
            if (inflag.f == cInFlag.Unknown)
            {
                System.Diagnostics.Debug.WriteLine("The boundaries of P and Q do not cross.");
                intersection = false;
            }
        }
예제 #26
0
 public ConvexHull2D(cVertexList list)
 {
     this.list = list;
 }
예제 #27
0
 public void ClearHull()
 {
     top = new cVertexList();
 }