Example #1
0
        /// <summary>
        /// 判断点P是否在圆内
        /// </summary>
        /// <param name="C">圆C</param>
        /// <param name="P">点P</param>
        /// <returns>如果在圆内返回True,否则返回False。</returns>
        public static Boolean InCircle(CircleI C, PointI P)
        {
            //判断点是否在圆内:
               //计算圆心到该点的距离,如果小于等于半径则该点在圆内。
            Double D = PointAlgorithm.Distance(P, C.Center);

            return((D < C.Radius) || DoubleAlgorithm.Equals(D, C.Radius));
        }
Example #2
0
 /// <summary>
 /// 判断点P,Q是否重合
 /// </summary>
 /// <param name="P">点P</param>
 /// <param name="Q">点Q</param>
 /// <returns>如果重合则返回True,否则返回False。</returns>
 public static Boolean Equals(PointD P, PointD Q)
 {
     if (DoubleAlgorithm.Equals(P.X, Q.X) == false)
     {
         return(false);
     }
     if (DoubleAlgorithm.Equals(P.Y, Q.Y) == false)
     {
         return(false);
     }
     return(true);
 }
        /// <summary>
        /// 判断圆C是否在多边形PG内
        /// </summary>
        /// <param name="PG">PG多边形</param>
        /// <param name="C">圆C</param>
        /// <returns>如果圆C在区域内返回True,否则返回False.</returns>
        public static Boolean InPolygon(PolygonI PG, CircleI C)
        {
            //如果圆心不在多边形内则返回不在多边形内
            if (false == InPolygon(PG, C.Center))
            {
                return(false);
            }
            Double D = PointAlgorithm.ClosestDistance(C.Center, PG);

            if (D > C.Radius || DoubleAlgorithm.Equals(D, C.Radius))
            {
                return(true);
            }
            return(false);
        }
Example #4
0
        /// <summary>
        /// 计算点 (0,0),P,Q,P+Q组成的平行四边形的带符号的面积
        /// P*Q = -(Q*P)
        /// </summary>
        /// <param name="P">点P</param>
        /// <param name="Q">点Q</param>
        /// <returns>返回面积值</returns>
        /// <remarks>
        /// 返回值 大于 0 , 则P在Q的顺时针方向。
        /// 返回值 等于 0 , 则P在Q的逆时针方向。
        /// 返回值 小于 0 , 则P与Q共线,但可能同向也可能反向。
        /// </remarks>
        public static Double Multiple(PointD P, PointD Q)
        {
            //formula
            //P × Q = x1*y2 - x2*y1
            //则矢量叉积定义为由(0,0)、P、Q和P+Q所组成的平行四边形的带符号的面积,即:P * Q = x1*y2 - x2*y1,其结果是一个标量
            //若 P * Q > 0 , 则P在Q的顺时针方向。
            //若 P * Q < 0 , 则P在Q的逆时针方向。
            //若 P * Q = 0 , 则P与Q共线,但可能同向也可能反向。
            Double result = (P.X * Q.Y - Q.X * P.Y);

            if (DoubleAlgorithm.Equals(result, 0) == true)
            {
                return(0);
            }
            return(result);
        }
Example #5
0
        /// <summary>
        /// 根据点P,Q,R三点确定一个圆,注意三点不能共线
        /// </summary>
        /// <param name="P">点P</param>
        /// <param name="Q">点Q</param>
        /// <param name="R">点R</param>
        /// <returns>返回圆,如果圆不存在则返回null.</returns>
        public static CircleD?CreateCircle(PointI P, PointI Q, PointI R)
        {
            if (DoubleAlgorithm.Equals(LineAlgorithm.Position(P, Q, R), 0))
            {
                return(null);                                                          //三点共线无法确定圆
            }
            //formula
            //(x-a)^2+(y-b)^2=r^2
            //f1:(x1-a)^2 + (y1-b)^2 = r^2
            //f2:(x2-a)^2 + (y2-b)^2 = r^2
            //f3:(x3-a)^2 + (y3-b)^2 = r^2
            //f1=f2: x1^2-2ax1+y1^2-2by1= x2^2-2ax2+y2^2-2by2;
            //a=(((X(1)^2-X(2)^2+Y(1)^2-Y(2)^2)*(Y(2)-Y(3)))-((X(2)^2-X(3)^2+Y(2)^2-Y(3)^2)*(Y(1)-Y(2))))/(2*(X(1)-X(2))*(Y(2)-Y(3))-2*(X(2)-X(3))*(Y(1)-Y(2)))
            //b=(((X(1)^2-X(2)^2+Y(1)^2-Y(2)^2)*(X(2)-X(3)))-((X(2)^2-X(3)^2+Y(2)^2-Y(3)^2)*(X(1)-X(2))))/(2*(Y(1)-Y(2))*(X(2)-X(3))-2*(Y(2)-Y(3))*(X(1)-X(2)))
            Double a = (Double)(((P.X * P.X - Q.X * Q.X + P.Y * P.Y - Q.Y * Q.Y) * (Q.Y - R.Y)) - ((Q.X * Q.X - R.X * R.X + Q.Y * Q.Y - R.Y * R.Y) * (P.Y - Q.Y))) / (Double)(2 * (P.X - Q.X) * (Q.Y - R.Y) - 2 * (Q.X - R.X) * (P.Y - Q.Y));
            Double b = (Double)(((P.X * P.X - Q.X * Q.X + P.Y * P.Y - Q.Y * Q.Y) * (Q.X - R.X)) - ((Q.X * Q.X - R.X * R.X + Q.Y * Q.Y - R.Y * R.Y) * (P.X - Q.X))) / (Double)(2 * (P.Y - Q.Y) * (Q.X - R.X) - 2 * (Q.Y - R.Y) * (P.X - Q.X));
            Double r = PointAlgorithm.Distance(P, new PointD(a, b));

            return(new CircleD(a, b, r));
        }
Example #6
0
        /// <summary>
        /// 判断线段L与圆C的交点个数
        /// </summary>
        /// <param name="L">线段L</param>
        /// <param name="C">圆形C</param>
        /// <returns>相交返回交点数目,否则返回0</returns>
        public static Int32?HasIntersection(LineI L, CircleI C)
        {
            Int32 count = 0;

            //如果和圆C有交点首先是L到圆心的距离小于或等于C的半径
            if (DoubleAlgorithm.Equals(PointAlgorithm.ClosestDistance(C.Center, L), C.Radius))
            {
                return(1);
            }
            else if (PointAlgorithm.ClosestDistance(C.Center, L) > C.Radius)
            {
                return(0);
            }
            if (PointAlgorithm.Distance(C.Center, L.Starting) >= C.Radius)
            {
                ++count;
            }
            if (PointAlgorithm.Distance(C.Center, L.End) >= C.Radius)
            {
                ++count;
            }
            return(count);
        }
Example #7
0
 /// <summary>
 /// 判断点P是否在圆边界上
 /// </summary>
 /// <param name="C">圆C</param>
 /// <param name="P">点P</param>
 /// <returns>如果在圆边界上返回True,否则返回False。</returns>
 public static Boolean OnCircle(CircleI C, PointI P)
 {
     return(DoubleAlgorithm.Equals(Distance(C, P), 0));
 }