Пример #1
0
        public static bool Intersect(PointLf ap1, PointLf ap2, PointLf bp1, PointLf bp2, ref PointLf ip)
        {
            const double intersectionEpsilon = 1.0e-30;

            double under = (bp2.Y - bp1.Y) * (ap2.X - ap1.X) - (bp2.X - bp1.X) * (ap2.Y - ap1.Y);

            if (under < intersectionEpsilon)
            {
                return(false);
            }

            double _t = (bp2.X - bp1.X) * (ap1.Y - bp1.Y) - (bp2.Y - bp1.Y) * (ap1.X - bp1.X);
            double _s = (ap2.X - ap1.X) * (ap1.Y - bp1.Y) - (ap2.Y - ap1.Y) * (ap1.X - bp1.X);

            double t = _t / under;
            double s = _s / under;

            if (t < 0.0 || t > 1.0 || s < 0.0 || s > 1.0)
            {
                return(false);
            }
            if (_t == 0 && _s == 0)
            {
                return(false);
            }

            ip.X = ap1.X + t * (double)(ap2.X - ap1.X);
            ip.Y = ap1.Y + t * (double)(ap2.Y - ap1.Y);

            return(true);
        }
Пример #2
0
        public static PointLf CalRotatedPointLf(PointLf ptStartPointLf, double fRotationDegree, bool cw)
        {
            var ptRotationCenter = new PointLf(0, 0);

            if (cw)
            {
                return(CalCWRotatedPointLf(ptStartPointLf, fRotationDegree, ptRotationCenter));
            }
            else
            {
                return(CalCCWRotatedPointLf(ptStartPointLf, fRotationDegree, ptRotationCenter));
            }
        }
Пример #3
0
        public static PointLf CalCCWRotatedPointLf(PointLf ptStartPointLf, double fRotationDegree, PointLf ptRotationCenter)
        {
            PointLf      ptDestPointLf = new PointLf(0, 0); //시작점과 회전각도로 계산할 끝점
            const double TWOPI         = Math.PI * 2;
            //끝점 계산
            //원점을 기준으로 {x, y}를 시계방향으로 a(radian)만큼 회전시킨 점을 구하는 공식.
            //x' = x*Math.Cos(a) + y*Math.Sin(a)
            //y' = -x*Math.Sin(a) + y*Math.Cos(a)
            double fTotalRotationRadian = fRotationDegree * TWOPI / 360;

            ptDestPointLf.X = (ptStartPointLf.X - ptRotationCenter.X) * Math.Cos(fTotalRotationRadian)
                              + (ptStartPointLf.Y - ptRotationCenter.Y) * Math.Sin(fTotalRotationRadian) + ptRotationCenter.X;
            ptDestPointLf.Y = -(ptStartPointLf.X - ptRotationCenter.X) * Math.Sin(fTotalRotationRadian)
                              + (ptStartPointLf.Y - ptRotationCenter.Y) * Math.Cos(fTotalRotationRadian) + ptRotationCenter.Y;
            return(ptDestPointLf);
        }
Пример #4
0
        public static bool Intersect(PointLf ap, PointLf bp, ref PointLf ip)
        {
            var zero = new PointLf(0, 0);

            return(Intersect(zero, ap, zero, bp, ref ip));
        }
Пример #5
0
        public static PointLf CalCCWRotatedPointLf(PointLf ptStartPointLf, double fRotationDegree)
        {
            var ptRotationCenter = new PointLf(0, 0);

            return(CalCCWRotatedPointLf(ptStartPointLf, fRotationDegree, ptRotationCenter));
        }