Пример #1
0
 /// <summary>
 /// ��鵱ǰԲ���Ƿ����ָ��ֱ��
 /// </summary>
 ///
 /// <param name="line"></param>
 /// <returns></returns>
 public bool Contains(Line line)
 {
     return Contains(line.GetX1(), line.GetY1())
             && Contains(line.GetX2(), line.GetY2());
 }
Пример #2
0
 public bool Intersects(Line other)
 {
     Vector2f lineSegmentStart = new Vector2f(other.GetX1(), other.GetY1());
     Vector2f lineSegmentEnd = new Vector2f(other.GetX2(), other.GetY2());
     Vector2f circleCenter = new Vector2f(GetCenterX(), GetCenterY());
     Vector2f closest;
     Vector2f segv = lineSegmentEnd.Cpy().Sub(lineSegmentStart);
     Vector2f ptv = circleCenter.Cpy().Sub(lineSegmentStart);
     float segvLength = segv.Len();
     float projvl = ptv.Dot(segv) / segvLength;
     if (projvl < 0)
     {
         closest = lineSegmentStart;
     }
     else if (projvl > segvLength)
     {
         closest = lineSegmentEnd;
     }
     else
     {
         Vector2f projv = segv.Cpy().Scale(projvl / segvLength);
         closest = lineSegmentStart.Cpy().Add(projv);
     }
     bool intersects = circleCenter.Cpy().Sub(closest).LengthSquared() <= GetRadius()
             * GetRadius();
     return intersects;
 }
Пример #3
0
        private bool Intersects(RectBox other)
        {
            RectBox box = other;
            Circle circle = this;

            if (box.Contains(x + radius, y + radius))
            {
                return true;
            }

            float x1 = box.GetX();
            float y1 = box.GetY();
            float x2 = box.GetX() + box.GetWidth();
            float y2 = box.GetY() + box.GetHeight();

            Line[] lines = new Line[4];
            lines[0] = new Line(x1, y1, x2, y1);
            lines[1] = new Line(x2, y1, x2, y2);
            lines[2] = new Line(x2, y2, x1, y2);
            lines[3] = new Line(x1, y2, x1, y1);

            float r2 = circle.GetRadius() * circle.GetRadius();

            Vector2f pos = new Vector2f(circle.GetCenterX(), circle.GetCenterY());

            for (int i = 0; i < 4; i++)
            {
                float dis = lines[i].DistanceSquared(pos);
                if (dis < r2)
                {
                    return true;
                }
            }

            return false;
        }
Пример #4
0
        public bool Includes(float x_0, float y_1)
        {
            if (points.Length == 0) {
                return false;
            }

            CheckPoints();

            Line testLine = new Line(0, 0, 0, 0);
            Vector2f pt = new Vector2f(x_0, y_1);

            for (int i = 0; i < points.Length; i += 2) {
                int n = i + 2;
                if (n >= points.Length) {
                    n = 0;
                }
                testLine.Set(points[i], points[i + 1], points[n], points[n + 1]);

                if (testLine.On(pt)) {
                    return true;
                }
            }

            return false;
        }
Пример #5
0
        public bool Intersect(Line other, bool limit, Vector2f result)
        {
            float dx1 = end.GetX() - start.GetX();
            float dx2 = other.end.GetX() - other.start.GetX();
            float dy1 = end.GetY() - start.GetY();
            float dy2 = other.end.GetY() - other.start.GetY();
            float denom = (dy2 * dx1) - (dx2 * dy1);

            if (denom == 0) {
                return false;
            }

            float ua = (dx2 * (start.GetY() - other.start.GetY()))
                    - (dy2 * (start.GetX() - other.start.GetX()));
            ua /= denom;
            float ub = (dx1 * (start.GetY() - other.start.GetY()))
                    - (dy1 * (start.GetX() - other.start.GetX()));
            ub /= denom;

            if ((limit) && ((ua < 0) || (ua > 1) || (ub < 0) || (ub > 1))) {
                return false;
            }

            float u = ua;

            float ix = start.GetX() + (u * (end.GetX() - start.GetX()));
            float iy = start.GetY() + (u * (end.GetY() - start.GetY()));

            result.Set(ix, iy);
            return true;
        }
Пример #6
0
        public Vector2f Intersect(Line other, bool limit)
        {
            Vector2f temp = new Vector2f();

            if (!Intersect(other, limit, temp)) {
                return null;
            }

            return temp;
        }
Пример #7
0
 public Vector2f Intersect(Line other)
 {
     return Intersect(other, false);
 }
Пример #8
0
 public Vector2f Intersect(Line other)
 {
     return(Intersect(other, false));
 }