Ejemplo n.º 1
0
        ///*Returns the distance of the input point
        // *from its perp. proj. to the e1 edge.
        // *Uses method detailed in comp.graphics.algorithms FAQ
        // */
        public float DistEdgePoint(cPointi a, cPointi b, cPointi c)
        {
            float r, s;
            float Length;
            float dproj = 0.0f;

            Length = Convert.ToSingle(Math.Sqrt(Math.Pow((b.X - a.X), 2) +
                                                Math.Pow((b.Y - a.Y), 2)));

            if (Length == 0)
            {
                System.Diagnostics.Debug.WriteLine("DistEdgePoint: Length = 0");
                a.PrintPoint();
                b.PrintPoint();
                c.PrintPoint();
            }
            r = (((a.Y - c.Y) * (a.Y - b.Y))
                 - ((a.X - c.X) * (b.X - a.X))) / (Length * Length);
            s = (((a.Y - c.Y) * (b.X - a.X))
                 - ((a.X - c.X) * (b.Y - a.Y))) / (Length * Length);

            dproj = Math.Abs(s * Length);

            //    System.Diagnostics.Debug.WriteLine("XI = " + (a.x + r *(b.x-a.x))+" YI = "+(a.y+r*(b.y-a.y)));
            if ((s != 0) && ((0.0 <= r) && (r <= 1)))
            {
                return(dproj);
            }
            if ((s == 0) && Between(a, b, c))
            {
                return(0.0f);
            }
            else
            {
                float ca = Dist(a, c);
                float cb = Dist(b, c);
                return(Math.Min(ca, cb));
            }
        }
Ejemplo n.º 2
0
 public void PrintVertex(int index)
 {
     System.Diagnostics.Debug.WriteLine("V" + index + " = ");
     Point.PrintPoint();
 }
Ejemplo n.º 3
0
        private int ReadVertices()
        {
            cVertex v = P.head;
            int     i = 0;

            do
            {
                v.IndexInPointCloud = 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.IndexInPointCloud = i++;
                v.IsProcessed       = false;
                v = v.NextVertex;
            } while (v != P.head);

            float xmin, ymin, xmax, ymax;     /* Primary min & max */
            float 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);
        }