Java 解圆方程

Java 解圆方程,java,geometry,quadratic,equation-solving,Java,Geometry,Quadratic,Equation Solving,我正在寻找用Java解决以下方程的帮助 (a-x1)^2 + (b-y1)^2 = r1^2 + r^2 (a-x2)^2 + (b-y2)^2 = r2^2 + r^2 (a-x3)^2 + (b-y3)^2 = r3^2 + r^2 已知x1,y1,r1,x2,y2,r2和x3,y3,r3的值。 我需要求解a,b,r 如何在Java中实现这一点?我检查了这个问题,但没有找到如何做到这一点。不过它对线性方程很有帮助。我想你需要线性方程来进行高斯消去 如果a,b,r是你需要解的,很明显,这些都

我正在寻找用Java解决以下方程的帮助

(a-x1)^2 + (b-y1)^2 = r1^2 + r^2
(a-x2)^2 + (b-y2)^2 = r2^2 + r^2
(a-x3)^2 + (b-y3)^2 = r3^2 + r^2
已知
x1
y1
r1
x2
y2
r2
x3
y3
r3
的值。 我需要求解
a
b
r


如何在Java中实现这一点?我检查了这个问题,但没有找到如何做到这一点。不过它对线性方程很有帮助。

我想你需要线性方程来进行高斯消去

如果a,b,r是你需要解的,很明显,这些都是非线性方程

你需要一个非线性解算器,比如牛顿·拉弗森

你得把方程线性化。计算微分da、db和dr的雅可比

您将从最初的猜测开始

a = a(old)
b = b(old)
r = r(old)
使用方程的线性化版本来计算增量

2*(a(old)-x1)*da + 2*(b(old)-y1)*db = 2*r(old)*dr
2*(a(old)-x2)*da + 2*(b(old)-y2)*db = 2*r(old)*dr
2*(a(old)-x3)*da + 2*(b(old)-y3)*db = 2*r(old)*dr
更新你的猜测

a(new) = a(old) + da
b(new) = b(old) + db
r(new) = r(old) + dr
然后重复,直到收敛(如果收敛)

永远不要用高斯消去法解线性方程组:它有很多问题。更好的方法是进行LU分解和前向-后向替换

如果我的线性化方程是正确的,它们的形式为
A(dx)=0
。边界条件应该是什么

(a,b)
是圆心的坐标
r
是半径


你真的有三个点吗?
(x1,y1)
(x2,y2)
,和
(x3,y3)
?或者你还有更多的分数吗?如果是后者,则需要进行最小二乘拟合。

希望此方法能为您提供一些想法:

public int[] getCoordinates(float XR_1, float YR_1, float XR_2, float YR_2,
                             float XR_3, float YR_3, int R1, int R2, int R3) {
    //define the positions
    int XU_1 = 0, YU_1 = 0, XU_2 = 0, YU_2 = 0, XU, YU;
    //define variables and arrays that needed
    float D0[][] = new float[17][50];
    float D1[][] = new float[17][50];
    float f[][] = new float[17][50];
    float fmin_1 = 0;
    float fmin_2 = 0;
    //define columns and rows
    int i, j;
    //Y goes from 0 to 49
    for(j=0; j<=49; j++){
        //X goes from 0 to 16
        for(i=0; i<=16; i++){
            D0[i][j] = (float) (Math.pow((i-XR_1),2) + Math.pow((j-YR_1),2) - Math.pow(R1,2));
            D1[i][j] = (float) (Math.pow((i-XR_2),2) + Math.pow((j-YR_2),2) - Math.pow(R2,2));
            f[i][j] = (float) Math.sqrt(Math.pow(D0[i][j], 2) + Math.pow(D1[i][j], 2));
            //get two position where f[i][j] are the minimum
            //initialise the minimum two positions
            if(i==0 & j==0){
                fmin_1 = f[i][j];
                XU_1 = i;
                YU_1 = j;
            }
            else if(j==0 & i==1){
                if(f[i][j] < fmin_1){
                    fmin_2 = fmin_1;
                    fmin_1 = f[i][j];
                    XU_2 = XU_1;
                    XU_1 = i;
                    YU_2 = YU_1;
                    YU_1 = j;
                }
                else {
                    fmin_2 = f[i][j];
                    XU_2 = i;
                    YU_2 = j;
                }
            }
            else{
                if(f[i][j] < fmin_1){
                    fmin_2 = fmin_1;
                    fmin_1 = f[i][j];
                    XU_2 = XU_1;
                    XU_1 = i;
                    YU_2 = YU_1;
                    YU_1 = j;
                }
                else if(f[i][j] < fmin_2){
                    fmin_2 = f[i][j];
                    XU_2 = i;
                    YU_2 = j;
                }
            }
        }
    }
public int[]getCoordinates(float XR_1、float YR_1、float XR_2、float YR_2、,
浮点数XR_3,浮点数YR_3,整数R1,整数R2,整数R3){
//确定位置
int XU_1=0,YU_1=0,XU_2=0,YU_2=0,XU,YU;
//定义所需的变量和数组
浮动D0[][]=新浮动[17][50];
浮动D1[][]=新浮动[17][50];
浮动f[][]=新浮动[17][50];
浮点数fmin_1=0;
浮点数fmin_2=0;
//定义列和行
int i,j;
//Y从0到49

对于(j=0;jMight想问+1高斯消去法肯定不行。这更像是一个数学/数值计算问题,而不是一个编程问题。大多数SO读者可能从来没有或忘记过如何做相关的数学。(包括我自己!)