三个点拟合圆形的函数C#

三个点拟合圆形的函数

函数说明

public void FitCircleFromThreePoints(double1X, double1Y, double2X, double2Y, double3X, double3Y, out double 圆心X坐标, out double 圆心Y坐标, out double 圆形半径大小)
 public void FitCircleFromThreePoints(double Points1X, double Points1Y, double Points2X, double Points2Y, double Points3X, double Points3Y, out double Col, out double Row, out double Rad)
        { 
            try
            { 
            //先判断一下这三个点是否共线,如果共线就不求了。
                if ((Points1X - Points2X) / (Points1Y - Points2Y) == (Points2X - Points3X) / (Points2Y - Points3Y))
                { 
                Col = 0;
                Row = 0;
                Rad = 0;
                    return ;
                }
                //求圆形
                double x1, y1, x2, y2, x3, y3;
                double a, b, c, g, h, f;
                x1 = Points1X;
                y1 = Points1Y;
                x2 = Points2X;
                y2 = Points2Y;
                x3 = Points3X;
                y3 = Points3Y;
                h = 2 * (x2 - x1);
                f = 2 * (y2 - y1);
                g = x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1;
                a = 2 * (x3 - x2);
                b = 2 * (y3 - y2);
                c = x3 * x3 - x2 * x2 + y3 * y3 - y2 * y2;
                Col = (g * b - c * f) / (h * b - a * f);
                Row = (a * g - c * h) / (a * f - b * h);
                Rad = Math.Sqrt((Col - x1) * (Col - x1) + (Row - y1) * (Row - y1));
            }
            catch
            { 
                Col = 0;
                Row = 0;
                Rad = 0;
            }
        }

不懂可以问我哈,底下评论留言,看到第一时间回复。觉得有用点赞哦。

PS

我的博客不定时分享日常工作中觉得有价值的内容,包括C#、C++、halcon、运动控制等等内容,喜欢的点赞,关注我。

    原文作者:小邢同学
    原文地址: https://blog.csdn.net/cashmood/article/details/102505311
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞