如果不赶时间可以自己推算出算式或者直接参考另一个博主的文章:
三点确定一个圆的计算方法_Ivan 的专栏-CSDN博客_三点确定一个圆
程序完整部分《C#已知三点求圆方程算法.rar》已经上传到CSDN,地址是:
在这里贴出算法部分:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DrawCircle
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
FirstPoint = new List<double>();
SecondPoint = new List<double>();
ThridPoint = new List<double>();
this.StartPosition = FormStartPosition.CenterScreen;//窗口居中
}
List<double> FirstPoint;
List<double> SecondPoint;
List<double> ThridPoint;
private void btn_Calculate_Click(object sender, EventArgs e)
{
//先清除上一次储存的数值
FirstPoint.Clear();
SecondPoint.Clear();
ThridPoint.Clear();
//把文本框的数值加入到数组中
try
{
//第一点的X Y坐标值
FirstPoint.Add(double.Parse(tb_FirstPointX.Text));
FirstPoint.Add(double.Parse(tb_FirstPointY.Text));
//第二点的X Y坐标值
SecondPoint.Add(double.Parse(tb_SecondPointX.Text));
SecondPoint.Add(double.Parse(tb_SecondPointY.Text));
//第三点的X Y坐标值
ThridPoint.Add(double.Parse(tb_ThirdPointX.Text));
ThridPoint.Add(double.Parse(tb_ThirdPointY.Text));
}
catch(Exception ex)
{
MessageBox.Show(ex.Message+"\n请重新输入","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
//算法内容
double a = FirstPoint[0] - SecondPoint[0];// X1-X2
double b = FirstPoint[1] - SecondPoint[1];//Y1-Y2
double c = FirstPoint[0] - ThridPoint[0];//X1-X3
double d = FirstPoint[1] - ThridPoint[1];//Y1-Y3
double aa = Math.Pow(FirstPoint[0], 2) - Math.Pow(SecondPoint[0], 2);//X1^2-X2^2
double bb = Math.Pow(SecondPoint[1], 2) - Math.Pow(FirstPoint[1], 2);//Y2^2-Y1^2
double cc = Math.Pow(FirstPoint[0], 2) - Math.Pow(ThridPoint[0], 2);//X1^2-X3^2
double dd = Math.Pow(ThridPoint[1], 2) - Math.Pow(FirstPoint[1], 2);//Y3^2-Y1^2
double E = (aa-bb) / 2;
double F = (cc-dd) / 2;
double resultY = (a * F - c * E) / (a * d - b * c);
double resultX = (F * b - E * d) / (b * c - a * d);
double resultR = Math.Sqrt((Math.Pow((FirstPoint[0] - resultX), 2)) + (Math.Pow((FirstPoint[1] - resultY), 2)));
//输出圆心的坐标和半径值
lb_Point.Text = "X坐标为:" + resultX.ToString() + "; Y坐标为:" + resultY.ToString();
lb_Radius.Text = resultR.ToString();
}
}
}