代码块:三点法计算圆心坐标和圆半径

北慕城南 提交于 2019-11-27 05:59:06

引用“System.Drawing”

using System.Drawing;
/// <summary>
/// 三点法计算圆心坐标和圆半径
/// </summary>
/// <param name="px1">第一个点</param>
/// <param name="px2">第二个点</param>
/// <param name="px3">第三个点</param>
/// <param name="X">圆心x坐标</param>
/// <param name="Y">圆心y坐标</param>
/// <param name="R">圆半径</param>
public void CalculateCicular(PointF px1, PointF px2, PointF px3, out float X, out float Y, out float R)
{
    float x1, y1, x2, y2, x3, y3;
    float a, b, c, g, e, f;
    x1 = px1.X;
    y1 = px1.Y;
    x2 = px2.X;
    y2 = px2.Y;
    x3 = px3.X;
    y3 = px3.Y;
    e = 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;
    X = (g * b - c * f) / (e * b - a * f);
    Y = (a * g - c * e) / (a * f - b * e);
    R = (float)Math.Sqrt((X - x1) * (X - x1) + (Y - y1) * (Y - y1));
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!