Пример #1
0
        /// <summary>
        /// 获取交点
        /// </summary>
        /// <param name="line"></param>
        /// <param name="intersectPoint"></param>
        /// <returns></returns>
        public bool GetIntersectPoint(Rays2D line, ref Double2 intersectPoint)
        {
            Double2 aixsVector = line.AixsVector(this.startPoint);
            double  distance   = aixsVector.magnitude;

            if (distance == 0)
            {
                intersectPoint = this.startPoint;
                return(true);
            }
            else
            {
                double dot = Double2.Dot(aixsVector.normalized, this.normalizedDir);
                if (dot < 0)
                {
                    Double2 point = this.startPoint - distance / dot * this.normalizedDir;
                    Double2 diff  = point - this.endPoint;
                    Double2 diff2 = point - line.startPoint;
                    if (Double2.Dot(this.normalizedDir, diff) <= 0 && Double2.Dot(diff2, line.normalizedDir) > 0)
                    {
                        intersectPoint = point;
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #2
0
 /// <summary>
 /// 射线与射线间的关系
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public LineRelation CheckLineRelation(Rays2D line)
 {
     // 共线判断
     if (Double2.CheckInLine(this.normalizedDir, line.normalizedDir) == true)
     {
         Double2 diff = line.startPoint - this.startPoint;
         // 共线判断
         if (Double2.CheckInLine(this.normalizedDir, diff) == true)
         {
             return(LineRelation.Coincide);
         }
         else
         {
             return(LineRelation.Parallel);
         }
     }
     else
     {
         // 先判断this 是否与line 所在直线相交
         Double2 aixsVector = line.AixsVector(this.startPoint);
         if (Double2.Dot(aixsVector, this.normalizedDir) > 0)
         {
             return(LineRelation.Detach);
         }
         // 先判断line 是否与this 所在直线相交
         aixsVector = this.AixsVector(line.startPoint);
         if (Double2.Dot(aixsVector, line.normalizedDir) > 0)
         {
             return(LineRelation.Detach);
         }
         return(LineRelation.Intersect);
     }
 }
Пример #3
0
        /// <summary>
        /// 直线与射线间的关系
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public override LineRelation CheckLineRelation(Rays2D line)
        {
            if (CheckIn(line.startPoint) == true)
            {
                return(LineRelation.Intersect);
            }
            double dis = line.AixsVector(this.circleCenter).sqrMagnitude - this.radius * this.radius;

            if (dis < 0)
            {
                Double2 diff = this.circleCenter - line.startPoint;
                if (Double2.Dot(diff, line.normalizedDir) > 0)
                {
                    return(LineRelation.Intersect);
                }
                else
                {
                    return(LineRelation.Detach);
                }
            }
            else
            {
                return(LineRelation.Detach);
            }
        }
Пример #4
0
 /// <summary>
 /// 射线与射线间的关系
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public LineRelation CheckLineRelation(Rays2D line)
 {
     // 共线判断
     if (Double2.CheckInLine(this.normalizedDir, line.normalizedDir) == true)
     {
         Double2 diff = line.startPoint - this.startPoint;
         // 贡献判断
         if (Double2.CheckInLine(this.normalizedDir, diff) == true)
         {
             return(LineRelation.Coincide);
         }
         else
         {
             return(LineRelation.Parallel);
         }
     }
     else
     {
         Double2 aixsVector1 = line.AixsVector(this.startPoint);
         Double2 aixsVector2 = line.AixsVector(this.endPoint);
         if (Double2.Dot(aixsVector1, aixsVector2) < 0)
         {
             Double2 aixsVector = this.AixsVector(line.startPoint);
             if (Double2.Dot(aixsVector, line.normalizedDir) > 0)
             {
                 return(LineRelation.Detach);
             }
             else
             {
                 return(LineRelation.Intersect);
             }
         }
         else
         {
             return(LineRelation.Detach);
         }
     }
 }