6 个解决方案
#1
中垂线的交点。
两点组成一条线段,线段可做中垂线,两中垂线有交点,即圆心
圆心到三点距离是半径
两点组成一条线段,线段可做中垂线,两中垂线有交点,即圆心
圆心到三点距离是半径
#2
斜率 (ya - yb) / (xa - xb) 中点 ((xa + xb) / 2, (ya + yb) / 2)
垂线斜率 = -1/斜率 = -(xa - xb) / (ya - yb)
所以中垂线方程: y - (ya + yb) / 2 = ( -(xa - xb) / (ya - yb)) * (x - (xa + xb) / 2)
两直线交点,就是解二元一次方程,自己想吧
垂线斜率 = -1/斜率 = -(xa - xb) / (ya - yb)
所以中垂线方程: y - (ya + yb) / 2 = ( -(xa - xb) / (ya - yb)) * (x - (xa + xb) / 2)
两直线交点,就是解二元一次方程,自己想吧
#3
A(x1,y1), B(x2,y2),C(x3,y3),
AB的中点M( (x1+x2)/2, (y1+y2)/2)
AB的斜率:k=(y2-y1)/(x2-x1)
AB的垂直平分线的斜率为:-1/k
因此由点斜式写出AB垂直平分线:y=-(x2-x1/(y2-y1)* [x-(x1+x2)/2]+(y1+y2)/2
同理得到AC垂直平分线:y=-(x3-x1/(y3-y1)* [x-(x1+x3)/2]+(y1+y3)/2
两垂直平分线交点就是圆心,二元一次方程应该会吧,得出的x、y就是圆心坐标
A、B、C任意一点到圆心的距离就是半径
啊!!我是来教数学的!
AB的中点M( (x1+x2)/2, (y1+y2)/2)
AB的斜率:k=(y2-y1)/(x2-x1)
AB的垂直平分线的斜率为:-1/k
因此由点斜式写出AB垂直平分线:y=-(x2-x1/(y2-y1)* [x-(x1+x2)/2]+(y1+y2)/2
同理得到AC垂直平分线:y=-(x3-x1/(y3-y1)* [x-(x1+x3)/2]+(y1+y3)/2
两垂直平分线交点就是圆心,二元一次方程应该会吧,得出的x、y就是圆心坐标
A、B、C任意一点到圆心的距离就是半径
啊!!我是来教数学的!
#4
其实计算圆心和坐标 只不过把数学的用代码展现出来 一样的
#5
class Program
{
static void Main(string[] args)
{
CircleInfo circle = new CircleInfo(new CPoint() { X = -2, Y = 0 }, new CPoint() { X = 0, Y = 2 }, new CPoint() { X = 2, Y = 0 });
Console.WriteLine(string.Format("CenterX:{0}\tCenterY:{1}\tRadius:{2}", circle.Center.X, circle.Center.Y, circle.Radius));
Console.ReadKey();
}
}
class CircleInfo
{
public CircleInfo(CPoint p1, CPoint p2, CPoint p3)
{
this.center = new CPoint();
if ((p2.X - p1.X) * (p3.Y - p1.Y) == (p2.Y - p1.Y) * (p3.X - p1.X))//三点在一条直线上
{
;
}
else
{
if (p2.Y - p1.Y != 0 && p3.Y - p1.Y != 0)
{
SetCircleInfo(p1, p2, p3);
}
else if (p1.Y - p2.Y != 0 && p3.Y - p2.Y != 0)
{
SetCircleInfo(p2, p1, p3);
}
else if (p2.Y - p3.Y != 0 && p1.Y - p3.Y != 0)
{
SetCircleInfo(p3, p2, p1);
}
}
}
private CPoint center;
public CPoint Center
{
get { return center; }
set { center = value; }
}
private double radius;
public double Radius
{
get { return radius; }
set { radius = value; }
}
void SetCircleInfo(CPoint p1, CPoint p2, CPoint p3)
{
double ratio1 = -(p2.X - p1.X) / (p2.Y - p1.Y);
double ratio2 = -(p3.X - p1.X) / (p3.Y - p1.Y);
CPoint cp1 = new CPoint() { X = 0.5 * (p1.X + p2.X), Y = 0.5 * (p1.Y + p2.Y) };
CPoint cp2 = new CPoint() { X = 0.5 * (p1.X + p3.X), Y = 0.5 * (p1.Y + p3.Y) };
center.X = (cp2.Y - cp1.Y + ratio1 * cp1.X - ratio2 * cp2.X) / (ratio1 - ratio2);
center.Y = ratio1 * (center.X - cp1.X) + cp1.Y;
radius = Math.Pow((p1.X - center.X) * (p1.X - center.X) + (p1.Y - center.Y) * (p1.Y - center.Y), 0.5);
}
}
class CPoint
{
public double X { get; set; }
public double Y { get; set; }
}
#6
double u = (y[1] - y[0]) / (x[1] - x[0]);
double v = (y[2] - y[1]) / (x[2] - x[1]);
double w = 0.5 * (y[0] + y[1]) + 0.5 * (x[0] + x[1]) / ((y[1] - y[0]) / (x[1] - x[0]));
double k = 0.5 * (y[1] + y[2]) + 0.5 * (x[1] + x[2]) / ((y[2] - y[1]) / (x[2] - x[1]));
double cx = (k - w) / (1 / v - 1 / u);
double cy = (w - k) / u / (1 / v - 1 / u) + w;
double r = Math.Sqrt(Math.Pow((y[0] - cy), 2) + Math.Pow((x[0] - cx), 2));
#1
中垂线的交点。
两点组成一条线段,线段可做中垂线,两中垂线有交点,即圆心
圆心到三点距离是半径
两点组成一条线段,线段可做中垂线,两中垂线有交点,即圆心
圆心到三点距离是半径
#2
斜率 (ya - yb) / (xa - xb) 中点 ((xa + xb) / 2, (ya + yb) / 2)
垂线斜率 = -1/斜率 = -(xa - xb) / (ya - yb)
所以中垂线方程: y - (ya + yb) / 2 = ( -(xa - xb) / (ya - yb)) * (x - (xa + xb) / 2)
两直线交点,就是解二元一次方程,自己想吧
垂线斜率 = -1/斜率 = -(xa - xb) / (ya - yb)
所以中垂线方程: y - (ya + yb) / 2 = ( -(xa - xb) / (ya - yb)) * (x - (xa + xb) / 2)
两直线交点,就是解二元一次方程,自己想吧
#3
A(x1,y1), B(x2,y2),C(x3,y3),
AB的中点M( (x1+x2)/2, (y1+y2)/2)
AB的斜率:k=(y2-y1)/(x2-x1)
AB的垂直平分线的斜率为:-1/k
因此由点斜式写出AB垂直平分线:y=-(x2-x1/(y2-y1)* [x-(x1+x2)/2]+(y1+y2)/2
同理得到AC垂直平分线:y=-(x3-x1/(y3-y1)* [x-(x1+x3)/2]+(y1+y3)/2
两垂直平分线交点就是圆心,二元一次方程应该会吧,得出的x、y就是圆心坐标
A、B、C任意一点到圆心的距离就是半径
啊!!我是来教数学的!
AB的中点M( (x1+x2)/2, (y1+y2)/2)
AB的斜率:k=(y2-y1)/(x2-x1)
AB的垂直平分线的斜率为:-1/k
因此由点斜式写出AB垂直平分线:y=-(x2-x1/(y2-y1)* [x-(x1+x2)/2]+(y1+y2)/2
同理得到AC垂直平分线:y=-(x3-x1/(y3-y1)* [x-(x1+x3)/2]+(y1+y3)/2
两垂直平分线交点就是圆心,二元一次方程应该会吧,得出的x、y就是圆心坐标
A、B、C任意一点到圆心的距离就是半径
啊!!我是来教数学的!
#4
其实计算圆心和坐标 只不过把数学的用代码展现出来 一样的
#5
class Program
{
static void Main(string[] args)
{
CircleInfo circle = new CircleInfo(new CPoint() { X = -2, Y = 0 }, new CPoint() { X = 0, Y = 2 }, new CPoint() { X = 2, Y = 0 });
Console.WriteLine(string.Format("CenterX:{0}\tCenterY:{1}\tRadius:{2}", circle.Center.X, circle.Center.Y, circle.Radius));
Console.ReadKey();
}
}
class CircleInfo
{
public CircleInfo(CPoint p1, CPoint p2, CPoint p3)
{
this.center = new CPoint();
if ((p2.X - p1.X) * (p3.Y - p1.Y) == (p2.Y - p1.Y) * (p3.X - p1.X))//三点在一条直线上
{
;
}
else
{
if (p2.Y - p1.Y != 0 && p3.Y - p1.Y != 0)
{
SetCircleInfo(p1, p2, p3);
}
else if (p1.Y - p2.Y != 0 && p3.Y - p2.Y != 0)
{
SetCircleInfo(p2, p1, p3);
}
else if (p2.Y - p3.Y != 0 && p1.Y - p3.Y != 0)
{
SetCircleInfo(p3, p2, p1);
}
}
}
private CPoint center;
public CPoint Center
{
get { return center; }
set { center = value; }
}
private double radius;
public double Radius
{
get { return radius; }
set { radius = value; }
}
void SetCircleInfo(CPoint p1, CPoint p2, CPoint p3)
{
double ratio1 = -(p2.X - p1.X) / (p2.Y - p1.Y);
double ratio2 = -(p3.X - p1.X) / (p3.Y - p1.Y);
CPoint cp1 = new CPoint() { X = 0.5 * (p1.X + p2.X), Y = 0.5 * (p1.Y + p2.Y) };
CPoint cp2 = new CPoint() { X = 0.5 * (p1.X + p3.X), Y = 0.5 * (p1.Y + p3.Y) };
center.X = (cp2.Y - cp1.Y + ratio1 * cp1.X - ratio2 * cp2.X) / (ratio1 - ratio2);
center.Y = ratio1 * (center.X - cp1.X) + cp1.Y;
radius = Math.Pow((p1.X - center.X) * (p1.X - center.X) + (p1.Y - center.Y) * (p1.Y - center.Y), 0.5);
}
}
class CPoint
{
public double X { get; set; }
public double Y { get; set; }
}
#6
double u = (y[1] - y[0]) / (x[1] - x[0]);
double v = (y[2] - y[1]) / (x[2] - x[1]);
double w = 0.5 * (y[0] + y[1]) + 0.5 * (x[0] + x[1]) / ((y[1] - y[0]) / (x[1] - x[0]));
double k = 0.5 * (y[1] + y[2]) + 0.5 * (x[1] + x[2]) / ((y[2] - y[1]) / (x[2] - x[1]));
double cx = (k - w) / (1 / v - 1 / u);
double cy = (w - k) / u / (1 / v - 1 / u) + w;
double r = Math.Sqrt(Math.Pow((y[0] - cy), 2) + Math.Pow((x[0] - cx), 2));