예제 #1
0
파일: Circle.cs 프로젝트: vb0067/LGame
        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);
        }
예제 #2
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());
 }
예제 #3
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;
 }
예제 #4
0
파일: Circle.cs 프로젝트: vb0067/LGame
 /// <summary>
 /// 检查当前圆形是否包含指定直线
 /// </summary>
 ///
 /// <param name="line"></param>
 /// <returns></returns>
 public bool Contains(Line line)
 {
     return(Contains(line.GetX1(), line.GetY1()) &&
            Contains(line.GetX2(), line.GetY2()));
 }