Exemplo n.º 1
0
 /** simple copy constructor */
 public Point_dt(Point_dt p)
 {
     X = p.X;
     Y = p.Y;
     Z = p.Z;
 }
Exemplo n.º 2
0
 public double distance2(Point_dt p)
 {
     return((p.X - X) * (p.X - X) + (p.Y - Y) * (p.Y - Y));
 }
Exemplo n.º 3
0
        /** @return the L2 distanse NOTE: 2D only!!! */
        public double distance(Point_dt p)
        {
            double temp = Math.Pow(p.x - X, 2) + Math.Pow(p.y - Y, 2);

            return(Math.Sqrt(temp));
        }
Exemplo n.º 4
0
        /**
         * tests the relation between this point (as a 2D [x,y] point) and a 2D
         * segment a,b (the Z values are ignored), returns one of the following:
         * LEFT, RIGHT, INFRONTOFA, BEHINDB, ONSEGMENT
         *
         * @param a
         *            the first point of the segment.
         * @param b
         *            the second point of the segment.
         * @return the value (flag) of the relation between this point and the a,b
         *         line-segment.
         */
        public int pointLineTest(Point_dt a, Point_dt b)
        {
            double dx  = b.X - a.X;
            double dy  = b.Y - a.Y;
            double res = dy * (X - a.X) - dx * (Y - a.Y);

            if (res < 0)
            {
                return(LEFT);
            }
            if (res > 0)
            {
                return(RIGHT);
            }

            if (dx > 0)
            {
                if (X < a.X)
                {
                    return(INFRONTOFA);
                }
                if (b.X < X)
                {
                    return(BEHINDB);
                }
                return(ONSEGMENT);
            }
            if (dx < 0)
            {
                if (X > a.X)
                {
                    return(INFRONTOFA);
                }
                if (b.X > X)
                {
                    return(BEHINDB);
                }
                return(ONSEGMENT);
            }
            if (dy > 0)
            {
                if (Y < a.Y)
                {
                    return(INFRONTOFA);
                }
                if (b.Y < Y)
                {
                    return(BEHINDB);
                }
                return(ONSEGMENT);
            }
            if (dy < 0)
            {
                if (Y > a.Y)
                {
                    return(INFRONTOFA);
                }
                if (b.Y > Y)
                {
                    return(BEHINDB);
                }
                return(ONSEGMENT);
            }
            Console.WriteLine("Error, pointLineTest with a=b");

            return(ERROR);
        }
Exemplo n.º 5
0
        /**
         * compute the Z value for the X,Y values of q.
         * assume this triangle represent a plane --> q does NOT need to be contained
         * in this triangle.
         *
         * @param q query point (its Z value is ignored).
         * @return q with updated Z value.
         *
         */
        public Point_dt z(Point_dt q)
        {
            double z = z_value(q);

            return(new Point_dt(q.x, q.y, z));
        }
Exemplo n.º 6
0
 /**
  * return true iff this point [x,y] coordinates are the same as p [x,y]
  * coordinates. (the z value is ignored).
  */
 public bool Equals(Point_dt p)
 {
     return((X == p.X) && (Y == p.Y));
 }
Exemplo n.º 7
0
 internal bool circumcircle_contains(Point_dt p)
 {
     return(circum.Radius() > circum.Center().distance2(p));
 }
Exemplo n.º 8
0
 /**
  * Copy Constructor. <br />
  * Creates a new Circle with same properties of <code>circ</code>.
  * @param circ Circle to clone.
  */
 public Circle_dt(Circle_dt circ)
 {
     this.c = circ.c;
     this.r = circ.r;
 }
Exemplo n.º 9
0
        /**
         *
         * @param p
         *            query point
         * @return true iff p is within this triangulation (in its 2D convex hull).
         */

        public bool contains(Point_dt p)
        {
            Triangle_dt tt = find(p);

            return(!tt.halfplane);
        }
Exemplo n.º 10
0
        /**
         *
         * @param q
         *            Query point
         * @return the q point with updated Z value (z value is as given the
         *         triangulation).
         */
        public Point_dt z(Point_dt q)
        {
            Triangle_dt t = find(q);

            return(t.z(q));
        }
Exemplo n.º 11
0
 /**
  * finds the triangle the query point falls in, note if out-side of this
  * triangulation a half plane triangle will be returned (see contains), the
  * search has expected time of O(n^0.5), and it starts form a fixed triangle
  * (this.startTriangle),
  *
  * @param p
  *            query point
  * @return the triangle that point p is in.
  */
 public Triangle_dt find(Point_dt p)
 {
     return(find(this.startTriangle, p));
 }
Exemplo n.º 12
0
 public Triangle_dt FastFind(Point_dt p)
 {
     return(find(gridPoints.FindClosestTriangle(p), p));
 }
Exemplo n.º 13
0
        private void insertCollinear(Point_dt p, int res)
        {
            Triangle_dt t, tp, u;

            switch (res)
            {
            case Point_dt.INFRONTOFA:
                t                    = new Triangle_dt(firstP, p);
                tp                   = new Triangle_dt(p, firstP);
                t.abnext             = tp;
                tp.abnext            = t;
                t.bcnext             = tp;
                tp.canext            = t;
                t.canext             = firstT;
                firstT.bcnext        = t;
                tp.bcnext            = firstT.abnext;
                firstT.abnext.canext = tp;
                firstT               = t;
                firstP               = p;
                break;

            case Point_dt.BEHINDB:
                t                   = new Triangle_dt(p, lastP);
                tp                  = new Triangle_dt(lastP, p);
                t.abnext            = tp;
                tp.abnext           = t;
                t.bcnext            = lastT;
                lastT.canext        = t;
                t.canext            = tp;
                tp.bcnext           = t;
                tp.canext           = lastT.abnext;
                lastT.abnext.bcnext = tp;
                lastT               = t;
                lastP               = p;
                break;

            case Point_dt.ONSEGMENT:
                u = firstT;
                while (p.isGreater(u.a))
                {
                    u = u.canext;
                }
                t                      = new Triangle_dt(p, u.b);
                tp                     = new Triangle_dt(u.b, p);
                u.b                    = p;
                u.abnext.a             = p;
                t.abnext               = tp;
                tp.abnext              = t;
                t.bcnext               = u.bcnext;
                u.bcnext.canext        = t;
                t.canext               = u;
                u.bcnext               = t;
                tp.canext              = u.abnext.canext;
                u.abnext.canext.bcnext = tp;
                tp.bcnext              = u.abnext;
                u.abnext.canext        = tp;
                if (firstT == u)
                {
                    firstT = t;
                }
                break;
            }
        }
Exemplo n.º 14
0
 internal bool isLess(Point_dt p)
 {
     return((X < p.X) || ((X == p.X) && (Y < p.Y)));
 }
Exemplo n.º 15
0
        /**
         * compute the Z value for the X,Y values of q. <br />
         * assume this triangle represent a plane --> q does NOT need to be contained
         * in this triangle.
         *
         * @param q query point (its Z value is ignored).
         * @return the Z value of this plane implies by this triangle 3 points.
         */
        public double z_value(Point_dt q)
        {
            if (q == null || this.halfplane)
            {
                throw new Exception("*** ERR wrong parameters, can't approximate the z value ..***: " + q);
            }

            /* incase the query point is on one of the points */
            if (q.x == a.x & q.y == a.y)
            {
                return(a.z);
            }
            if (q.x == b.x & q.y == b.y)
            {
                return(b.z);
            }
            if (q.x == c.x & q.y == c.y)
            {
                return(c.z);
            }

            /*
             *  plane: aX + bY + c = Z:
             *  2D line: y= mX + k
             *
             */
            double X = 0, x0 = q.x, x1 = a.x, x2 = b.x, x3 = c.x;
            double Y = 0, y0 = q.y, y1 = a.y, y2 = b.y, y3 = c.y;
            double Z = 0, m01 = 0, k01 = 0, m23 = 0, k23 = 0;

            // 0 - regular, 1-horisintal , 2-vertical.
            int flag01 = 0;

            if (x0 != x1)
            {
                m01 = (y0 - y1) / (x0 - x1);
                k01 = y0 - m01 * x0;
                if (m01 == 0)
                {
                    flag01 = 1;
                }
            }
            else
            {               // 2-vertical.
                flag01 = 2; //x01 = x0
            }
            int flag23 = 0;

            if (x2 != x3)
            {
                m23 = (y2 - y3) / (x2 - x3);
                k23 = y2 - m23 * x2;
                if (m23 == 0)
                {
                    flag23 = 1;
                }
            }
            else
            {               // 2-vertical.
                flag23 = 2; //x01 = x0
            }

            if (flag01 == 2)
            {
                X = x0;
                Y = m23 * X + k23;
            }
            else
            {
                if (flag23 == 2)
                {
                    X = x2;
                    Y = m01 * X + k01;
                }
                else
                {  // regular case
                    X = (k23 - k01) / (m01 - m23);
                    Y = m01 * X + k01;
                }
            }
            double r = 0;

            if (flag23 == 2)
            {
                r = (y2 - Y) / (y2 - y3);
            }
            else
            {
                r = (x2 - X) / (x2 - x3);
            }
            Z = b.z + (c.z - b.z) * r;
            if (flag01 == 2)
            {
                r = (y1 - y0) / (y1 - Y);
            }
            else
            {
                r = (x1 - x0) / (x1 - X);
            }
            double qZ = a.z + (Z - a.z) * r;

            return(qZ);
        }
Exemplo n.º 16
0
 internal bool isGreater(Point_dt p)
 {
     return((X > p.X) || ((X == p.X) && (Y > p.Y)));
 }
Exemplo n.º 17
0
 //* Constructor. <br />
 //* Constructs a new Circle_dt.
 //* @param c Center of the circle.
 //* @param r Radius of the circle.
 public Circle_dt(Point_dt c, double r)
 {
     this.c = c;
     this.r = r;
 }