当以正确的方式表述时,多边定位问题是一个优化问题。
大多数学术例子,例如维基百科 https://en.wikipedia.org/wiki/Trilateration,处理恰好三个圆圈并假设完全准确的信息。这些情况允许更简单的问题表述和准确的答案,并且通常不能满足您所描述的实际情况。
The problem in R2 or R3 euclidean space with distances that contain measurement error, an area (ellipse) or volume (ellipsoid) of interest is usually obtained instead of a point. If a point estimate is desired instead of a region, the area centroid or volume centroid should be used. R2 space requires at least 3 non-degenerate points and distances to obtain a unique region; and similarly R3 space requires at least 4 non-degenerate points and distances to obtain a unique region.
这是一个开源的java库,可以轻松满足您的需求:https://github.com/lemmingapex/Trilateration https://github.com/lemmingapex/Trilateration
它使用流行的非线性最小二乘优化器,即来自 Apache Commons Math 的 Levenberg-Marquardt 算法。
double[][] positions = new double[][] { { 5.0, -6.0 }, { 13.0, -15.0 }, { 21.0, -3.0 }, { 12.42, -21.2 } };
double[] distances = new double[] { 8.06, 13.97, 23.32, 15.31 };
NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(new TrilaterationFunction(positions, distances), new LevenbergMarquardtOptimizer());
Optimum optimum = solver.solve();
// the answer
double[] calculatedPosition = optimum.getPoint().toArray();
// error and geometry information
RealVector standardDeviation = optimum.getSigma(0);
RealMatrix covarianceMatrix = optimum.getCovariances(0);