Exemplo n.º 1
0
        public bool Collides(Rectangle r)
        {
            Vector2 r1 = new Vector2(r.X, r.Y);
            Vector2 r2 = new Vector2(r.X + r.Width, r.Y);
            Vector2 r3 = new Vector2(r.X + r.Width, r.Y - r.Height);
            Vector2 r4 = new Vector2(r.X, r.Y - r.Height);

            LineSeg l1 = new LineSeg(r1, r2);
            LineSeg l2 = new LineSeg(r2, r3);
            LineSeg l3 = new LineSeg(r3, r4);
            LineSeg l4 = new LineSeg(r4, r1);

            return(Intersects(l1) || Intersects(l2) || Intersects(l3) || Intersects(l4));
        }
Exemplo n.º 2
0
        public bool Intersects(LineSeg line)
        {
            bool intersects = false;

            Vector2 q1 = line.P1;
            Vector2 q2 = line.P2;

            int o1 = getOrientation(P1, P2, q1);
            int o2 = getOrientation(P1, P2, q2);
            int o3 = getOrientation(q1, q2, P1);
            int o4 = getOrientation(q1, q2, P2);

            if (o1 != o2 && o3 != o4)
            {
                intersects = true;
            }

            // Collinear
            if (o1 == 0 && OnSeg(q1))
            {
                intersects = true;
            }
            else if (o2 == 0 && OnSeg(q2))
            {
                intersects = true;
            }
            else if (line.OnSegment(P1))
            {
                intersects = true;
            }
            else if (line.OnSegment(P2))
            {
                intersects = true;
            }

            return(intersects);
        }