/**
         * Fit a circle to three given points on the circumference. The method draws lines (chords)
         * between two pairs of the points, constructs their perpendicular bisectors, and finds the
         * intersection point of those two lines. This is the centre of the circle as radii passing
         * through the centre are perpendicular bisectors of chords in a circle. The radius is the
         * distance between the centre and any one of the initial three points.
         */
        private QDCircle threePointCircleFit(List <QDPoint> pts)
        {
            QDLine         l1     = new QDLine(pts[0], pts[1]);
            QDLine         l2     = new QDLine(pts[1], pts[2]);
            QDInfiniteLine i1     = new QDInfiniteLine(l1.getMidpoint(), l1.getPerpAngleD());
            QDInfiniteLine i2     = new QDInfiniteLine(l2.getMidpoint(), l2.getPerpAngleD());
            QDPoint        centre = i1.intersect(i2);
            float          radius = QDUtils.QDUtils.getPtToPtDist(centre, pts[0]);

            return(new QDCircle(centre, radius));
        }
Exemple #2
0
        public void getIntrinsicConstraints(QDInputPointSet ptSet)
        {
            if (ptSet.shapeType == QDShapeTypes.LINE)
            {
                QDLine line  = (QDLine)ptSet.initialFit;
                float  angle = line.angleD;
                // Check for vertical line and adjust by midpoint pivot
                if ((90.0f - line_snap_thresh < angle && angle < 90.0f + line_snap_thresh) ||
                    (-90.0f - line_snap_thresh < angle && angle < -90.0f + line_snap_thresh) && !line.vertical)
                {
                    QDPoint newStart, newFinish;

                    if (line.start.y > line.getMidpoint().y)
                    {
                        newStart  = new QDPoint(line.midPoint.x, line.midPoint.y + (0.5f * line.length));
                        newFinish = new QDPoint(line.midPoint.x, line.midPoint.y - (0.5f * line.length));
                    }
                    else
                    {
                        newStart  = new QDPoint(line.midPoint.x, line.midPoint.y - (0.5f * line.length));
                        newFinish = new QDPoint(line.midPoint.x, line.midPoint.y + (0.5f * line.length));
                    }
                    ptSet.fittedShape = new QDLine(newStart, newFinish);
                    ptSet.constraints.Add(QDConstraintTypes.VERTICAL_LINE);
                }
                // Check for horizontal line and adjust by midpoint pivot
                else if ((-line_snap_thresh < angle && angle < line_snap_thresh) ||
                         (180.0f - line_snap_thresh < angle || angle < -180.0f + line_snap_thresh))
                {
                    float   length    = (float)Math.Sqrt(Math.Pow(line.start.x - line.finish.x, 2.0f) + Math.Pow(line.start.y - line.finish.y, 2.0f));
                    QDPoint midPt     = new QDPoint((line.start.x + line.finish.x) * 0.5f, (line.start.y + line.finish.y) * 0.5f);
                    QDPoint newStart  = new QDPoint();
                    QDPoint newFinish = new QDPoint();
                    newStart.y = newFinish.y = midPt.y;
                    if (line.start.x > midPt.x)
                    {
                        newStart.x  = midPt.x + (0.5f * length);
                        newFinish.x = midPt.x - (0.5f * length);
                    }
                    else
                    {
                        newStart.x  = midPt.x - (0.5f * length);
                        newFinish.x = midPt.x + (0.5f * length);
                    }
                    ptSet.fittedShape = new QDLine(newStart, newFinish);
                    ptSet.constraints.Add(QDConstraintTypes.HORIZONTAL_LINE);
                }
            }
        }