C++ 同一直线上3个圆的交点-三边测量

C++ 同一直线上3个圆的交点-三边测量,c++,geolocation,trilateration,C++,Geolocation,Trilateration,我遇到了一个问题:我想计算三个圆的交点。就我所知,我应该使用所谓的。我已经在C++中实现了它。报告说,这种解决方案有三个局限性 所有三个中心都在平面z=0内 球体中心P1位于原点 球体中心P2位于x轴上 至于第一个“标准”,我无事可做,因为所有三个中心都在平面z=0内,因为我不使用z坐标。 之后,我将点转换到第一个点(P1)的中心位于原点的位置。之后,我将P2(以及P3)点旋转到P2位于x轴上的位置 我的问题是:当所有三个中心都在X轴上时,我试图计算相交区域的中心(使用的算法是计算的),但计算无

我遇到了一个问题:我想计算三个圆的交点。就我所知,我应该使用所谓的。我已经在C++中实现了它。报告说,这种解决方案有三个局限性

  • 所有三个中心都在平面z=0内
  • 球体中心P1位于原点
  • 球体中心P2位于x轴上
  • 至于第一个“标准”,我无事可做,因为所有三个中心都在平面z=0内,因为我不使用z坐标。 之后,我将点转换到第一个点(P1)的中心位于原点的位置。之后,我将P2(以及P3)点旋转到P2位于x轴上的位置

    我的问题是:当所有三个中心都在X轴上时,我试图计算相交区域的中心(使用的算法是计算的),但计算无法完成。另一方面,没有限制,比如说“圆心不能在一条线上。。。 让我们直观地看一下我的问题,我刚刚画了它:

    如您所见,三个圆在(4,3)坐标处的同一点上相互相交。因此,这些点都在同一条线上(在本例中,在x轴上)有一个解决方案。 圆的参数如下(x,y,半径):

    正如我所提到的,我成功地实现了的算法,但它不能解决这个例子,结果是NaN(不是一个数字)。当然,我已经用另一个圆(不在同一条线上)尝试了这个算法,它工作正常

    因此,我开始调试我的实现,并找到了问题所在。我的实现如下所示:

    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <math.h> 
    #include <vector>
    std::ifstream infile("coordinateList.txt");
    using namespace std;
    
    std::vector<double> trilateration2D(double point1[], double point2[], double point3[], double r1, double r2, double r3) {
        std::vector<double> resultPose;
        //unit vector in a direction from point1 to point 2
        double p2p1Distance = pow(pow(point2[0]-point1[0],2) + pow(point2[1]-point1[1],2),0.5);
        double exx = (point2[0]-point1[0])/p2p1Distance;
        double exy = (point2[1]-point1[1])/p2p1Distance;
    
        //signed magnitude of the x component
        double ix = exx*(point3[0]-point1[0]);
        double iy = exy*(point3[1]-point1[1]);
        double i = ix+iy;
        //the unit vector in the y direction. 
        double eyx = (point3[0]-point1[0]-ix*exx)/pow(pow(point3[0]-point1[0]-ix*exx,2) + pow(point3[1]-point1[1]-iy*exy,2),0.5);
        double eyy = (point3[1]-point1[1]-iy*exy)/pow(pow(point3[0]-point1[0]-ix*exx,2) + pow(point3[1]-point1[1]-iy*exy,2),0.5);
        //the signed magnitude of the y component
        double jx = eyx*(point3[0]-point1[0]);
        double jy = eyy*(point3[1]-point1[1]);
        double j = jx + jy;
        //coordinates
        double x = (pow(r1,2) - pow(r2,2) + pow(p2p1Distance,2))/ (2 * p2p1Distance);
        double y = (pow(r1,2) - pow(r3,2) + pow(i,2) + pow(j,2))/(2*j) - i*x/j;
        //result coordinates
        double finalX = point1[0]+ x*exx + y*eyx;
        double finalY = point1[1]+ x*exy + y*eyy;
        resultPose.push_back(finalX);
        resultPose.push_back(finalY);
        return resultPose;
    }
    int main(int argc, char* argv[]){
        std::vector<double> finalPose;
        double p1[] = {0,0};
        double p2[] = {4,0};
        double p3[] = {8,0};
        double r1,r2,r3;
        r1 = 5;
        r2 =3;
        r3 = 5;
        finalPose = trilateration2D(p1,p2,p3,r1,r2,r3);
        cout<<"X:::  "<<finalPose[0]<<endl;
        cout<<"Y:::  "<<finalPose[1]<<endl;
    
    }
    
    #包括
    #包括
    #包括
    #包括
    #包括
    std::ifstream infle(“coordinateList.txt”);
    使用名称空间std;
    标准:向量三边测量2D(双点1[],双点2[],双点3[],双r1,双r2,双r3){
    std::载体结果糖;
    //从点1到点2方向上的单位矢量
    双p2p1Distance=pow(pow(点2[0]-点1[0],2)+pow(点2[1]-点1[1],2),0.5);
    double exx=(点2[0]-点1[0])/p2p1距离;
    双exy=(点2[1]-点1[1])/p2p1距离;
    //x分量的符号幅值
    双ix=exx*(点3[0]-点1[0]);
    双iy=exy*(点3[1]-点1[1]);
    双i=ix+iy;
    //y方向上的单位向量。
    双eyx=(点3[0]-点1[0]-ix*exx)/pow(pow(点3[0]-点1[0]-ix*exx,2)+pow(点3[1]-点1[1]-iy*exy,2),0.5);
    双eyy=(点3[1]-1[1]-iy*exy)/pow(pow(点3[0]-1[0]-ix*exx,2)+pow(点3[1]-1[1]-iy*exy,2),0.5);
    //y分量的符号大小
    双jx=eyx*(点3[0]-点1[0]);
    双jy=eyy*(点3[1]-点1[1]);
    双j=jx+jy;
    //坐标
    双x=(功率(r1,2)-功率(r2,2)+功率(p2p1距离,2))/(2*p2p1距离);
    双y=(pow(r1,2)-pow(r3,2)+pow(i,2)+pow(j,2))/(2*j)-i*x/j;
    //结果坐标
    双finalX=point1[0]+x*exx+y*eyx;
    double finalY=point1[1]+x*exy+y*eyy;
    结果:向后推(finalX);
    结果:推后(最终);
    返回结果集;
    }
    int main(int argc,char*argv[]){
    std::载体终糖;
    双p1[]={0,0};
    双p2[]={4,0};
    双p3[]={8,0};
    双r1,r2,r3;
    r1=5;
    r2=3;
    r3=5;
    最终结果=三边测量2D(p1、p2、p3、r1、r2、r3);
    
    顺便说一句,你要知道,既然你要求所有的圆都以x轴为中心,你实际上只需要找到两个圆的交点,第三个是多余的。如果它们的中心是任意的,你就需要第三个圆。哦,你说得对,谢谢:)
    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <math.h> 
    #include <vector>
    std::ifstream infile("coordinateList.txt");
    using namespace std;
    
    std::vector<double> trilateration2D(double point1[], double point2[], double point3[], double r1, double r2, double r3) {
        std::vector<double> resultPose;
        //unit vector in a direction from point1 to point 2
        double p2p1Distance = pow(pow(point2[0]-point1[0],2) + pow(point2[1]-point1[1],2),0.5);
        double exx = (point2[0]-point1[0])/p2p1Distance;
        double exy = (point2[1]-point1[1])/p2p1Distance;
    
        //signed magnitude of the x component
        double ix = exx*(point3[0]-point1[0]);
        double iy = exy*(point3[1]-point1[1]);
        double i = ix+iy;
        //the unit vector in the y direction. 
        double eyx = (point3[0]-point1[0]-ix*exx)/pow(pow(point3[0]-point1[0]-ix*exx,2) + pow(point3[1]-point1[1]-iy*exy,2),0.5);
        double eyy = (point3[1]-point1[1]-iy*exy)/pow(pow(point3[0]-point1[0]-ix*exx,2) + pow(point3[1]-point1[1]-iy*exy,2),0.5);
        //the signed magnitude of the y component
        double jx = eyx*(point3[0]-point1[0]);
        double jy = eyy*(point3[1]-point1[1]);
        double j = jx + jy;
        //coordinates
        double x = (pow(r1,2) - pow(r2,2) + pow(p2p1Distance,2))/ (2 * p2p1Distance);
        double y = (pow(r1,2) - pow(r3,2) + pow(i,2) + pow(j,2))/(2*j) - i*x/j;
        //result coordinates
        double finalX = point1[0]+ x*exx + y*eyx;
        double finalY = point1[1]+ x*exy + y*eyy;
        resultPose.push_back(finalX);
        resultPose.push_back(finalY);
        return resultPose;
    }
    int main(int argc, char* argv[]){
        std::vector<double> finalPose;
        double p1[] = {0,0};
        double p2[] = {4,0};
        double p3[] = {8,0};
        double r1,r2,r3;
        r1 = 5;
        r2 =3;
        r3 = 5;
        finalPose = trilateration2D(p1,p2,p3,r1,r2,r3);
        cout<<"X:::  "<<finalPose[0]<<endl;
        cout<<"Y:::  "<<finalPose[1]<<endl;
    
    }