Exemplo n.º 1
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);
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        private int ReadVertices()
        {
            cVertex v = P.head;
            int     i = 0;

            do
            {
                v.IndexInModel = i++;
                v.IsProcessed  = true;
                v = v.NextVertex;
            } while (v != P.head);

            v = B.head;
            do
            {
                cVertex temp = new cVertex(v.Point.X, v.Point.Y);
                P.InsertBeforeHead(temp);
                v = v.NextVertex;
            } while (v != B.head);

            v = P.GetElement(n); i = 0;
            do
            {
                /* Reflect secondary polygon */
                v.Point.X      = -v.Point.X;
                v.Point.Y      = -v.Point.Y;
                v.IndexInModel = i++;
                v.IsProcessed  = false;
                v = v.NextVertex;
            } while (v != P.head);

            double xmin, ymin, xmax, ymax;     /* Primary min & max */
            double sxmin, symin, sxmax, symax; /* Secondary min & max */
            int    mp, ms;                     /* i index of max (u-r) primary and secondary points */

            xmin  = ymin = xmax = ymax = 0;
            sxmin = symin = sxmax = symax = 0;
            mp    = ms = 0; v = P.head;
            xmin  = xmax = v.Point.X;
            ymin  = ymax = v.Point.Y;
            mp    = 0; i = 1;
            v     = v.NextVertex;
            cVertex startB = P.GetElement(n);

            do
            {
                if (v.Point.X > xmax)
                {
                    xmax = v.Point.X;
                }
                else if (v.Point.X < xmin)
                {
                    xmin = v.Point.X;
                }
                if (v.Point.Y > ymax)
                {
                    ymax = v.Point.Y; mp = i;
                }
                else if (v.Point.Y == ymax && (v.Point.X > P.GetElement(mp).Point.X))
                {
                    mp = i;
                }
                else if (v.Point.Y < ymin)
                {
                    ymin = v.Point.Y;
                }
                v = v.NextVertex; i++;
            } while (v != startB);
            /*System.Diagnostics.Debug.WriteLine("Index of upper rightmost primary, i=mp = "+mp);*/
            v     = startB;
            sxmin = sxmax = v.Point.X;
            symin = symax = v.Point.Y;
            ms    = n; v = v.NextVertex; i = 1;
            do
            {
                if (v.Point.X > sxmax)
                {
                    sxmax = v.Point.X;
                }
                else if (v.Point.X < sxmin)
                {
                    sxmin = v.Point.X;
                }
                if (v.Point.Y > symax)
                {
                    symax = v.Point.Y; ms = i;
                }
                else if (v.Point.Y == symax && (v.Point.X > P.GetElement(ms).Point.X))
                {
                    ms = i;
                }
                else if (v.Point.Y < symin)
                {
                    symin = v.Point.Y;
                }
                v = v.NextVertex; i++;
            } while (v != P.head.NextVertex);
            /*System.Diagnostics.Debug.WriteLine("Index of upper rightmost secondary, i=ms = "+ms);*/

            /* Compute the start point: upper rightmost of both. */
            System.Diagnostics.Debug.WriteLine("p0:");
            p0.PrintPoint();
            System.Diagnostics.Debug.WriteLine("mp is: " + mp);
            System.Diagnostics.Debug.WriteLine("mp element:" + P.GetElement(mp).Point.X + "," + P.GetElement(mp).Point.Y);
            AddVec(p0, P.GetElement(mp).Point, p0);
            System.Diagnostics.Debug.WriteLine("p0 after addvec:");
            p0.PrintPoint();
            System.Diagnostics.Debug.WriteLine("ms is: " + ms);
            System.Diagnostics.Debug.WriteLine("ms element:" + P.GetElement(ms).Point.X + "," + P.GetElement(ms).Point.Y);
            //   AddVec( p0, P.GetElement(ms).v, p0 );
            System.Diagnostics.Debug.WriteLine("p0 after another addvec:");
            p0.PrintPoint();
            return(mp);
        }
Exemplo n.º 4
0
        private void PutInOutput(double x, double y)
        {
            cVertex v = new cVertex(x, y);

            output.InsertBeforeHead(v);
        }
Exemplo n.º 5
0
        private void InsertInters(double x, double y)
        {
            cVertex v = new cVertex((int)x, (int)y);

            inters.InsertBeforeHead(v);
        }
Exemplo n.º 6
0
 private void Push(cVertex p, cVertexList top)
 {
     //simulating a stack behavior for cVertexList list
     //Push procedure
     top.InsertBeforeHead(p);
 }