一旦你得到你的距離,你可以使用下面的代碼示例找到trilaterated點的座標
{
//Declarations
//include the math.h header file
double xa=0, ya=0; //Co-ordinates of 1st ACCESS Point(preferably set as origin)
double xb=10,yb=0; //Co-ordinates of 2nd ACCESS Point
double xc=5,yc=10; //Co-ordinates of 3rd ACCESS Point
double triPt[2]={0,0}; //Trilaterated point
double p1[2]={xa,ya};
double p2[2]={xb,yb};
double p3[2]={xc,yc};
double ex[2],ey[2],ez[2];
double i=0,k=0,x=0,y=0;
double distA=5*1.41; //Distance from API 1 (Measured using RSSI values)
double distB=5*1.41; //""""" 2
double distC=5; //""""" 3
//Transforms to find circles around the three access points
//Here it is assumed that all access points and the trilaterated point are in the same plane
for(int j=0;j<2;j++)
{
ex[j]=p2[j]-p1[j];
}
double d=sqrt(pow(ex[0],2)+pow(ex[1],2));
for(int j=0;j<2;j++)
{
ex[j]=ex[j]/(sqrt(pow(ex[0],2)+pow(ex[1],2)));
}
for(int j=0;j<2;j++)
{
i=i+(p3[j]-p1[j])*ex[j];
}
for(int j=0;j<2;j++)
{
ey[j]=p3[j]-p1[j]-i*ex[j];
}
for(int j=0;j<2;j++)
{
ey[j]=ey[j]/(sqrt(pow(ey[0],2)+pow(ey[1],2)));
}
for(int j=0;j<2;j++)
{
k=k+(ey[j]*(p3[j]-p1[j]));
}
x=(pow(distA,2)-pow(distB,2)+pow(d,2))/(2*d);
y=((pow(distA,2)-pow(distC,2)+pow(i,2)+pow(k,2))/(2*k))-((i/k)*x);
//Calculating the co-ordinates of the point to be trilaterated
for(int j=0;j<3;j++)
{
triPt[j]=p1[j]+x*ex[j]+y*ey[j];
}
//Print the values
cout<<triPt[0]<<endl<<triPt[1];
getch();
return 0;
}