예제 #1
0
        //calculate the point of intersection between two line segments
        public Point2D intersection(Line2D L, out bool found)
        {
            Point2D pt = new Point2D(0.0, 0.0);
            Point2D A = p1;
            Point2D B = p2;
            Point2D C = L.p1;
            Point2D D = L.p2;

            double rTop = (A.y - C.y) * (D.x - C.x) - (A.x - C.x) * (D.y - C.y);
            double rBot = (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x);

            double sTop = (A.y - C.y) * (B.x - A.x) - (A.x - C.x) * (B.y - A.y);
            double sBot = (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x);

            if ((rBot == 0 || sBot == 0))
            {
                found = false;
                return pt;
            }
            double r = rTop / rBot;
            double s = sTop / sBot;
            if ((r > 0) && (r < 1) && (s > 0) && (s < 1))
            {
                pt.x = A.x + r * (B.x - A.x);
                pt.y = A.y + r * (B.y - A.y);
                found = true;
                return pt;
            }
            else
            {
                found = false;
                return pt;
            }
        }
예제 #2
0
 public Line2D(Line2D other)
 {
     p1 = other.p1;
     p2 = other.p2;
 }