Example #1
0
        /// <summary>
        /// 根据三个点来更新圆弧
        /// </summary>
        public void UpdateArcFrom3Points()
        {
            //Console.WriteLine("UpdateArcFrom3Points()");
            m_center   = HitUtil.CenterPointFrom3Points(m_p1, m_p2, m_p3);
            m_radius   = (float)HitUtil.Distance(m_center, m_p1);
            StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p1, 0));
            EndAngle   = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p3, 0));
            // find angle from P1 on line P1|P3 to P2. If this angle is 0-180 the direction is CCW else it is CW

            double p1p3angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p3, 0));
            double p1p2angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p2, 0));
            double diff      = p1p3angle - p1p2angle;

            //我知道这个逻辑存在问题,在某些情况下,圆弧的绘制不跟随鼠标,
            //但是现在也会奏效。
            Direction = eDirection.kCCW;
            if (diff < 0 || diff > 180)
            {
                Direction = eDirection.kCW;
            }

            if (p1p3angle == 0)
            {
                if (diff < -180)
                {
                    Direction = eDirection.kCCW;
                }
                else
                {
                    Direction = eDirection.kCW;
                }
            }
            if (p1p3angle == 90)
            {
                if (diff < -180)
                {
                    Direction = eDirection.kCCW;
                }
            }
        }
        public void UpdateArcFrom3Points()
        {
            m_center   = HitUtil.CenterPointFrom3Points(m_p1, m_p2, m_p3);
            m_radius   = (float)HitUtil.Distance(m_center, m_p1);
            StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p1, 0));
            EndAngle   = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p3, 0));
            // find angle from P1 on line P1|P3 to P2. If this angle is 0-180 the direction is CCW else it is CW

            double p1p3angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p3, 0));
            double p1p2angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p2, 0));
            double diff      = p1p3angle - p1p2angle;

            // I know there is a problem with this logic, in some cases the arc does not follow the mouse,
            // but it will work for now.
            Direction = eDirection.kCCW;
            if (diff < 0 || diff > 180)
            {
                Direction = eDirection.kCW;
            }

            if (p1p3angle == 0)
            {
                if (diff < -180)
                {
                    Direction = eDirection.kCCW;
                }
                else
                {
                    Direction = eDirection.kCW;
                }
            }
            if (p1p3angle == 90)
            {
                if (diff < -180)
                {
                    Direction = eDirection.kCCW;
                }
            }
        }
Example #3
0
        public void UpdateArcFrom3Points()
        {
            try
            {
                m_center   = HitUtil.CenterPointFrom3Points(m_p1, m_p2, m_p3);
                m_radius   = (float)HitUtil.Distance(m_center, m_p1);
                StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p1, 0));
                EndAngle   = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_center, m_p3, 0));
                double p1p3angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p3, 0));
                double p1p2angle = HitUtil.RadiansToDegrees(HitUtil.LineAngleR(m_p1, m_p2, 0));
                double diff      = p1p3angle - p1p2angle;
                Direction = eDirection.kCCW;
                if (diff < 0 || diff > 180)
                {
                    Direction = eDirection.kCW;
                }

                if (p1p3angle == 0)
                {
                    if (diff < -180)
                    {
                        Direction = eDirection.kCCW;
                    }
                    else
                    {
                        Direction = eDirection.kCW;
                    }
                }
                if (p1p3angle == 90)
                {
                    if (diff < -180)
                    {
                        Direction = eDirection.kCCW;
                    }
                }
            }
            catch (Exception ex)
            { throw ex; }
        }
Example #4
0
 public void UpdateCircleFrom3Points()
 {
     m_center = HitUtil.CenterPointFrom3Points(m_p1, m_p2, m_p3);
     m_radius = (float)HitUtil.Distance(m_center, m_p1);
 }