예제 #1
0
 // Construct an elliptical arc as a segment of an existing ellipse object
 public QDEllipticalArc(QDEllipse parent, SweepDirection dir, float startAngle, float finishAngle)
 {
     constructFromFoci(parent.mFoci1, parent.mFoci2, parent.mFociToCirc);
     direction     = dir;
     mStartAngleD  = startAngle;
     mFinishAngleD = finishAngle;
 }
        /**
         * Finds the beginning angle of an elliptical arc given its direction, searching points near
         * the first drawn point in case of small backtracks
         */
        private float findArcEndD(SweepDirection direction, QDInputPointSet ptSet, QDEllipse ellipse)
        {
            float finishAngle = QDUtils.QDUtils.getPtToPtAngleD(ellipse.mCentre, ptSet.pts.Last());

            if (direction == SweepDirection.Clockwise)
            {
                // Check for any points near the first point more CCW than the current to set as start
                for (int i = ptSet.pts.Count - 2; i > Math.Floor(ptSet.pts.Count * 0.75f); i--)
                {
                    float thisAngle = QDUtils.QDUtils.getPtToPtAngleD(ellipse.mCentre, ptSet.pts[i]);
                    if (QDUtils.QDUtils.angleDiffMinorD(finishAngle, thisAngle) < 0f)
                    {
                        finishAngle = thisAngle;
                    }
                }
            }
            else if (direction == SweepDirection.Counterclockwise)
            {     // CCW arc
                for (int i = ptSet.pts.Count - 2; i > Math.Floor(ptSet.pts.Count * 0.75f); i--)
                {
                    float thisAngle = QDUtils.QDUtils.getPtToPtAngleD(ellipse.mCentre, ptSet.pts[i]);
                    if (QDUtils.QDUtils.angleDiffMinorD(finishAngle, thisAngle) > 0f)
                    {
                        finishAngle = thisAngle;
                    }
                }
            }
            return(finishAngle);
        }
        /**
         * Finds the final angle of an elliptical arc given its direction, searching points near
         * the last drawn point in case of small backtracks
         */
        private float findArcStartD(SweepDirection direction, QDInputPointSet ptSet, QDEllipse ellipse)
        {
            float startAngle = QDUtils.QDUtils.getPtToPtAngleD(ellipse.mCentre, ptSet.pts[0]);

            if (direction == SweepDirection.Clockwise)
            {
                // Check for any points near the first point more CCW than the current to set as start
                for (int i = 1; i < Math.Ceiling(ptSet.pts.Count * 0.25f); i++)
                {
                    float thisAngle = QDUtils.QDUtils.getPtToPtAngleD(ellipse.mCentre, ptSet.pts[i]);
                    if (QDUtils.QDUtils.angleDiffMinorD(startAngle, thisAngle) > 0f)
                    {
                        startAngle = thisAngle;
                    }
                }
            }
            else if (direction == SweepDirection.Counterclockwise)
            {     // CCW arc
                for (int i = 1; i < Math.Ceiling(ptSet.pts.Count * 0.25f); i++)
                {
                    float thisAngle = QDUtils.QDUtils.getPtToPtAngleD(ellipse.mCentre, ptSet.pts[i]);
                    if (QDUtils.QDUtils.angleDiffMinorD(startAngle, thisAngle) < 0f)
                    {
                        startAngle = thisAngle;
                    }
                }
            }
            return(startAngle);
        }
        /**
         * Find angle swept by points around the centre of an elliptical arc. Used to determine
         * Whether it should be treated as a full ellipse or an arc
         */
        private float findSweptArc(QDInputPointSet ptSet, QDEllipse ellipse)
        {
            QDPoint        centre = ellipse.mCentre;
            List <QDPoint> pts    = ptSet.pts;

            float lastAngle  = QDUtils.QDUtils.getPtToPtAngleD(pts[0], centre);
            float angleSweep = 0f;

            foreach (QDPoint pt in pts)
            {
                float angle = QDUtils.QDUtils.getPtToPtAngleD(pt, centre);
                angleSweep += QDUtils.QDUtils.angleDiffMinorD(angle, lastAngle);
                lastAngle   = angle;
            }

            return(angleSweep);
        }