C# 求解三元一次方程组

C# 求解三元一次方程组

 /// 
 /// 求三元一次方程组
 /// 
 /// 三个点的X坐标
 /// 三个点的Y坐标
 /// 返回a,b,c
public static double[] solutionLinearEqations(double[] xParams, double[] yParams)
{
     double a = Math.Pow(xParams[0], 2);
     double b = xParams[0];
     double c = 1;
     double a1 = yParams[0];

     double d = Math.Pow(xParams[1], 2);
     double e = xParams[1];
     double f = 1;
     double b1 = yParams[1];

     double g = Math.Pow(xParams[2], 2);
     double h = xParams[2];
     double i = 1;
     double c1 = yParams[2];

     double A = a * (e * i - h * f) + b * (g * f - d * i) + c * (d * h - g * e);

     double x = (a1 * (e * i - h * f) + b1 * (h * c - b * i) + c1 * (b * f - e * c)) / A;
     double y = (a1 * (g * f - d * i) + b1 * (a * i - g * c) + c1 * (d * c - a * f)) / A;
     double z = (a1 * (d * h - g * e) + b1 * (g * b - a * h) + c1 * (a * e - b * d)) / A;

     return new double[] { x, y, z };
 }

点个关注吧

你可能感兴趣的:(算法)