Esempio n. 1
0
        public bool IsLineSegmentIntersect(LineSegment lineA)
        {
            var a = new SimplePoint(X1 - lineA.X1, Y1 - lineA.Y1);
            var b = new SimplePoint(lineA.X2 - lineA.X1, lineA.Y2 - lineA.Y1);
            var c = new SimplePoint(X2 - X1, Y2 - Y1);

            var ab = a.X * b.Y - a.Y * b.X;
            var ac = a.X * c.Y - a.Y * c.X;
            var bc = b.X * c.Y - b.Y * c.X;

            if (ab == 0)
            {
                // Lines are collinear, and so intersect if they have any overlap
                return(((X1 - lineA.X1 < 0) != (X1 - lineA.X2 < 0)) ||
                       ((Y1 - lineA.Y1 < 0) != (Y1 - lineA.Y2 < 0)));
            }

            if (bc == 0)
            {
                return(false); // Lines are parallel.
            }
            float d = 1f / bc;
            float e = ac * d;
            float f = ab * d;

            return((e >= 0f) && (e <= 1f) && (f >= 0f) && (f <= 1f));
        }
Esempio n. 2
0
 protected bool Equals(SimplePoint other)
 {
     return(X == other.X && Y == other.Y);
 }
Esempio n. 3
0
 public Shape(int totalSides)
 {
     Points = new SimplePoint[totalSides];
     Lines  = new LineSegment[totalSides];
 }