Hi all,
I am looking a trilateration algorithm that can use 3 position (Vector3) with its 3 radius or any other algorithm for calculate centroid of 3 position (Vector3) with its 3 radius.
For the moment i use this algorithm:
public static Vector3 GetTrilaterationPosition(Vector3 beaconA, Vector3 beaconB, Vector3 beaconC, float radiusA, float radiusB, float radiusC)
{
//PARAMETERS
float bAlat = beaconA.x;
float bAlong = beaconA.z;
float bBlat = beaconB.x;
float bBlong = beaconB.z;
float bClat = beaconC.x;
float bClong = beaconC.z;
//TEST 1
float W, Z, foundBeaconLat, foundBeaconLong, foundBeaconLongFilter;
W = radiusA * radiusA - radiusB * radiusB - bAlat * bAlat - bAlong * bAlong + bBlat * bBlat + bBlong * bBlong;
Z = radiusB * radiusB - radiusC * radiusC - bBlat * bBlat - bBlong * bBlong + bClat * bClat + bClong * bClong;
foundBeaconLat = (W * (bClong - bBlong) - Z * (bBlong - bAlong)) / (2 * ((bBlat - bAlat) * (bClong - bBlong) - (bClat - bBlat) * (bBlong - bAlong)));
foundBeaconLong = (W - 2 * foundBeaconLat * (bBlat - bAlat)) / (2 * (bBlong - bAlong));
//foundBeaconLongFilter` is a second measure of foundBeaconLong to mitigate errors
foundBeaconLongFilter = (Z - 2 * foundBeaconLat * (bClat - bBlat)) / (2 * (bClong - bBlong));
foundBeaconLong = (foundBeaconLong + foundBeaconLongFilter) / 2;
var foundLocation = new Vector3();
foundLocation.x = (foundBeaconLat);
foundLocation.z = (foundBeaconLong);
return foundLocation;
}
But it’s not much precise and sometimes the calculation throw bad positions, i am not very good with mathematics =(
Any suggestion or advice?
Sorry for my english.