三个点拟合圆形的函数C#
生活随笔
收集整理的這篇文章主要介紹了
三个点拟合圆形的函数C#
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
三個(gè)點(diǎn)擬合圓形的函數(shù)
函數(shù)說明
public void FitCircleFromThreePoints(double 點(diǎn)1X, double 點(diǎn)1Y, double 點(diǎn)2X, double 點(diǎn)2Y, double 點(diǎn)3X, double 點(diǎn)3Y, out double 圓心X坐標(biāo), out double 圓心Y坐標(biāo), 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{//先判斷一下這三個(gè)點(diǎn)是否共線,如果共線就不求了。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;}}不懂可以問我哈,底下評(píng)論留言,看到第一時(shí)間回復(fù)。覺得有用點(diǎn)贊哦。
PS
我的博客不定時(shí)分享日常工作中覺得有價(jià)值的內(nèi)容,包括C#、C++、halcon、運(yùn)動(dòng)控制等等內(nèi)容,喜歡的點(diǎn)贊,關(guān)注我。
總結(jié)
以上是生活随笔為你收集整理的三个点拟合圆形的函数C#的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 获得变量的名称获得传入参数的参数类型与堆
- 下一篇: halcon联合C#测量十字Mark中心