Exemple #1
0
    //
    // Interface

    public static void RegressEllipsePoints(Point[] points,
                                            out double x2, out double xy, out double y2, out double x1, out double y1, out double c0)
    {
        int n = points.Length;

        // Solve using QrDecomposition (least-squares regression)
        LeastSquaresRegression.Matrix lhs = new LeastSquaresRegression.Matrix(n, 5);

        for (int i = 0; i < n; ++i)
        {
            Point p = points[i];
            lhs[i, 0] = p.X * p.X;
            lhs[i, 1] = p.X * p.Y;
            lhs[i, 2] = p.Y * p.Y;
            lhs[i, 3] = p.X;
            lhs[i, 4] = p.Y;
        }

        LeastSquaresRegression.Matrix rhs = new LeastSquaresRegression.Matrix(n, 1);
        for (int i = 0; i < n; ++i)
        {
            rhs[i, 0] = -1.0;
        }

        LeastSquaresRegression.Matrix sln = lhs.Solve(rhs);

        x2 = sln[0, 0]; xy = sln[1, 0]; y2 = sln[2, 0]; x1 = sln[3, 0]; y1 = sln[4, 0]; c0 = 1.0;

        EllipseAnalysis.NormalizeCoeffs(ref x2, ref xy, ref y2, ref x1, ref y1, ref c0);
    }
    //
    // Interface
    public static void RegressEllipsePoints(Point[] points, 
		out double x2, out double xy, out double y2, out double x1, out double y1, out double c0)
    {
        int n = points.Length;

        // Solve using QrDecomposition (least-squares regression)
        LeastSquaresRegression.Matrix lhs = new LeastSquaresRegression.Matrix(n,5);

        for (int i=0; i<n; ++i)
        {
            Point p = points[i];
            lhs[i,0] = p.X*p.X;
            lhs[i,1] = p.X*p.Y;
            lhs[i,2] = p.Y*p.Y;
            lhs[i,3] = p.X;
            lhs[i,4] = p.Y;
        }

        LeastSquaresRegression.Matrix rhs = new LeastSquaresRegression.Matrix(n,1);
        for (int i=0; i<n; ++i)
            rhs[i,0] = -1.0;

        LeastSquaresRegression.Matrix sln = lhs.Solve(rhs);

        x2 = sln[0,0]; xy = sln[1,0]; y2 = sln[2,0]; x1 = sln[3,0]; y1 = sln[4,0]; c0 = 1.0;

        EllipseAnalysis.NormalizeCoeffs(ref x2, ref xy, ref y2, ref x1, ref y1, ref c0);
    }