コード例 #1
0
ファイル: CGeometry.cs プロジェクト: simawulei/HelloGit
        static public bool GetArcByPoint(GE_Point pt1, GE_Point pt2, GE_Point pt3, out GE_Point ptCenter)
        {
            bool bRet = false;

            ptCenter = new GE_Point();

            GE_Line   lin1 = new GE_Line();
            GE_Line   lin2 = new GE_Line();
            GE_Point  ptM1 = Geo.AcGeMidPoint(pt1, pt2);
            GE_Point  ptM2 = Geo.AcGeMidPoint(pt2, pt3);
            GE_Vector vp   = Geo.GetVector(pt1, pt2);

            vp.RotateBy(PI2);
            lin1.set(ptM1, ptM1 + vp * 100.0);
            vp = Geo.GetVector(pt2, pt3);
            vp.RotateBy(PI2);
            lin2.set(ptM2, ptM2 + vp * 100.0);
            GE_Point ptCen1, ptCen2;
            int      nRet = lin1.intersectWith(lin2, out ptCen1, out ptCen2);

            if (nRet > 0)
            {
                ptCenter = ptCen1;
                bRet     = true;
            }
            return(bRet);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="lin"></param>
        /// <param name="ptInt1"></param>
        /// <param name="ptInt2"></param>
        /// <returns></returns>
        public int intersectWith(GE_Line lin, out GE_Point ptInt1, out GE_Point ptInt2)
        {
            int nRet = 0;

            ptInt1 = new GE_Point(0, 0);
            ptInt2 = new GE_Point(0, 0);
            double A, B, a, b, c, d, P, Q, AA, BB, CC, X1, X2, Y1, Y2;

            double u;

            if (m_Kind == 0 && lin.m_Kind == 0)
            {
                PointF point1 = new PointF((float)m_StartPoint.X, (float)m_StartPoint.Y);
                PointF point2 = new PointF((float)m_EndPoint.X, (float)m_EndPoint.Y);
                PointF point3 = new PointF((float)lin.m_StartPoint.X, (float)lin.m_StartPoint.Y);
                PointF point4 = new PointF((float)lin.m_EndPoint.X, (float)lin.m_EndPoint.Y);

                PointF pointResult;
                if (GetIntersection(point1, point2, point3, point4, out pointResult))
                {
                    ptInt1.X = pointResult.X;
                    ptInt1.Y = pointResult.Y;
                    nRet     = 1;
                }


                //double x11, y11, x12, y12, x21, y21, x22, y22;

                //x11 = m_StartPoint.X;
                //y11 = m_StartPoint.Y;
                //x12 = m_EndPoint.X;
                //y12 = m_EndPoint.Y;
                //x21 = lin.m_StartPoint.X;
                //y21 = lin.m_StartPoint.Y;
                //x22 = lin.m_EndPoint.X;
                //y22 = lin.m_EndPoint.Y;

                //u = (x11 - x21) / ((x22 - x21) - (x12 - x11));
                //ptInt1.X = x11 + u * (x12 - x11);
                //ptInt1.Y = y11 + u * (y12 - y11);
                //nRet = 1;
            }
            else if (m_Kind == 1 && lin.m_Kind == 1)
            {
                A = m_CenterPoint.distanceTo(m_StartPoint);
                B = lin.m_CenterPoint.distanceTo(lin.m_StartPoint);
                a = m_CenterPoint.X;
                b = m_CenterPoint.Y;
                c = lin.m_CenterPoint.X;
                d = lin.m_CenterPoint.Y;

                P  = ((A * A - B * B) - (a * a + b * b - c * c - d * d)) / (2 * d - 2 * b);
                Q  = (c - a) / (d - b);
                AA = 1 + Q * Q;
                BB = 2 * b * Q - 2 * P * Q - 2 * a;
                CC = P * P - 2 * b * P - A * A + a * a + b * b;
                if (BB * BB - 4 * AA * CC > 0)
                {
                    X1       = (BB * -1 + Math.Sqrt(BB * BB - 4 * AA * CC)) / (2 * AA);
                    X2       = (BB * -1 - Math.Sqrt(BB * BB - 4 * AA * CC)) / (2 * AA);
                    Y1       = P - Q * X1;
                    Y2       = P - Q * X2;
                    ptInt1.X = X1; ptInt1.Y = Y1;
                    ptInt2.X = X2; ptInt2.Y = Y2;
                    nRet     = 2;
                }
                else
                {
                    nRet = 0;
                }
            }

            return(nRet);
        }