Skip to content

v2.0.0

Latest

Choose a tag to compare

@lemmingapex lemmingapex released this 24 Nov 22:12
· 20 commits to master since this release

The first major release since 2017: a rewrite with a new, self-contained API. It solves positions more reliably, reports how uncertain they are, handles outliers, and works with latitude and longitude. Requires Java 17 or newer.

implementation("com.lemmingapex.trilateration:trilateration:2.0.0")
TrilaterationResult result = new TrilaterationSolver().solve(positions, distances);

double[] point = result.getPoint();
double[] ci95 = result.getConfidenceHalfWidths(0.95).get();   // x ± ci95[0], y ± ci95[1]

Highlights

  • More reliable solutions. The optimizer starts from a closed-form linear estimate instead of the anchors' centroid. A second "mirror check" run then avoids the most common wrong answer, the mirror image of the true position.
  • Ambiguity warnings. When the anchors are (nearly) on a line in 2D or a plane in 3D, isAmbiguous() and getAlternativePoint() report the other position that fits the measurements about as well.
  • Uncertainty you can use. Covariance, standard deviations and confidence intervals are in distance units. You can give a standard deviation for each measurement to weight them by 1 / sigma².
  • Outlier handling. RobustLoss.HUBER and RobustLoss.CAUCHY limit the influence of bad distances, such as a blocked or reflected radio signal.
  • Latitude and longitude. GeodeticFrame converts WGS84 coordinates to a local frame in metres and back.
  • SVG output. TrilaterationSvg draws a 2D result: distance circles, the estimate and its confidence region, residuals, and the alternative position. It needs no graphics libraries.

Upgrading from 1.x

The 1.x classes are gone, and no Apache Commons Math or Hipparchus types appear in the API any more.

// 1.x
NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(
        new TrilaterationFunction(positions, distances), new LevenbergMarquardtOptimizer());
Optimum optimum = solver.solve();
double[] point = optimum.getPoint().toArray();
RealVector sigma = optimum.getSigma(0);

// 2.0
TrilaterationResult result = new TrilaterationSolver().solve(positions, distances);
double[] point = result.getPoint();
double[] sigma = result.getStandardDeviation().orElseThrow();

Behaviour changes to check:

  • Standard deviations and covariance have different values. In 1.x they were unscaled. Now they are in distance units, scaled by the standard deviations you give or, if you give none, by the noise level estimated from the residuals. When they can't be estimated, the accessors return an empty Optional instead of throwing.
  • Different error model. The solver minimizes range errors ||x − p_i|| − r_i instead of squared-distance errors. Well-posed problems give the same answer; noisy or degenerate ones may differ, usually for the better.
  • Stricter input checks, no side effects. Input arrays are copied and never modified. Negative, NaN and infinite values throw IllegalArgumentException; zero distances are accepted. If the optimizer fails, it throws TrilaterationException.
  • Removed: NonLinearLeastSquaresSolver, LinearLeastSquaresSolver, the public TrilaterationFunction, and the debugInfo options that printed to standard output.
  • Dependency: Apache Commons Math 3 has been replaced by Hipparchus 4, as an internal dependency. If you added Commons Math only to call this library, you can remove it.

Fixes

  • Collinear (2D) or coplanar (3D) anchors could leave the optimizer between the two possible solutions, matching neither.
  • TrilaterationFunction modified the caller's distances array.
  • LinearLeastSquaresSolver returned the first anchor's position when its system was singular.

See the README for full usage and the changelog for every change.

Full diff: v1.0.2...v2.0.0