Code Monkey home page Code Monkey logo

trilateration's Introduction

Trilateration

Build Status License

alt text

Solves a formulation of n-D space trilateration problem using a nonlinear least squares optimizer.

Input: positions, distances
Output: centroid with geometry and error

Uses Levenberg-Marquardt algorithm from Apache Commons Math.

double[][] positions = new double[][] { { 5.0, -6.0 }, { 13.0, -15.0 }, { 21.0, -3.0 }, { 12.4, -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[] centroid = optimum.getPoint().toArray();

// error and geometry information; may throw SingularMatrixException depending the threshold argument provided
RealVector standardDeviation = optimum.getSigma(0);
RealMatrix covarianceMatrix = optimum.getCovariances(0);

The multilateration problem can be formulated as an optimization problem and solved using Non-linear least squares methods. A well-formed solution will be an ellipse in R2, or an ellipsoid in R3. If you are only interested in a maximum likelihood point estimate, the centroid is also provided. 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.

Getting Trilateration

To add a dependency on Trilateration using Maven, use the following:

<dependency>
    <groupId>com.lemmingapex.trilateration</groupId>
    <artifactId>trilateration</artifactId>
    <version>1.0.2</version>
</dependency>

To add a dependency using Gradle:

dependencies {
  implementation 'com.lemmingapex.trilateration:trilateration:1.0.2'
}

Run the tests

*nix

./gradlew clean
./gradlew test -i

Windows

./gradlew.bat clean
./gradlew.bat test -i

trilateration's People

Contributors

hamz-a avatar kburfi avatar lemmingapex avatar matheusntg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trilateration's Issues

How to get ellipse from trilateration?

Hi! Thank you for the great library!
But I have a question. There is no problems with getting centroid from trilateration. But how can I get ellipse? I see that the result of trilateration is Optimum, but I can't understand how to get from there something except centroid.
Thank you!

SingularMatrixException on Error Calculation

Hi Scott,

It seems the following two lines both give a SingularMatrixException when run:

// error and geometry information
RealVector standardDeviation = optimum.getSigma(0);
RealMatrix covarianceMatrix = optimum.getCovariances(0);

I cannot get it to work with any input data. For example, here are some positions that throw the error (these are a Mercator projection of GPS coordinates):
Positions[0]:
0 = -4565919.193832541
1 = 1.6141672528603023E7
2 = 2200.0

Positions[1]:
0 = -4565920.313515583
1 = 1.6141679993156526E7
2 = 2200.0

Positions[2]:
0 = -4565927.778069112
1 = 1.6141678948119089E7
2 = 2200.0

Positions[3]:
0 = -4565926.658386086
1 = 1.6141671334274463E7
2 = 2200.0

Distances:
0 = 1.6
1 = 1.6
2 = 1.6
3 = 1.6

Would you have any idea as to why this might be the case? This is running on Android with the same (recently updated) Apache commons Math3 library you are using. It also doesn't work with the previous version of the library.

Calculating the point estimate works perfectly fine.

Regards,

Blair

Possibility to use relative distances

I wanted to inquire if I can use relative distances instead of real distances with the solution.

The case is mainly related to RSSI which is a relative value to indicate the distance between two targets (points). For example, if I have three base station A(0,0), B(10,10), C(5,5), and a device may say the RSSI-A is -60, RSSI-B is -70 and RSSI-C is -80. Thus, I just know the proportions of the distance which is D(A):D(B):D(C)=6:7:8 in the example but the real distances.

Swift/Objective-C version?

Is there any swift or objective-c version of this library?
I want to use the same algorithm in my iOS app.

Incorrect calculation of centroid.

I tried using this project for a given set of co ordinates and rssi values(which is later transformed into distance in meters)

double[][] positions = new double[][]{ {49.8773045,8.654494}, {49.877183,8.6547037} {{49.8772021,8.6548117}}; double[] rssi = new double[]{-69.0, -61.0,-81.0}; // After transformation the rssi values equate to double[] distance = new double[]{14.0,10.0,15.0}

The calculated centroid co ordinates are 48.263028853759394, 12.457544241370318 which locates to some other country. Could you look into this issue ?

Little Doubt

Hi,

Just to confirm. The distances are in meters?
Thank you so much!

What are the positions for?

I should have clarified, im using your library along with my own BLE beacons, to use trilateration in order to track my location.
If i want to place my beacons inside a room, using the coordinates, how do i know which coordinate belongs to which beacon im using?
in this:
image

Question about distances

Are the input distances computed from the TDOA? if so, why do we need same number of distances than receiver positions, as in reality we would need 1 distance less? Could you help me out please?

How to determine the accuracy of the coordinate

As this gives an optimized centroid I would be interested in any suitable idea on how to determine the accuracy of the result coordinate in case i can provide the real coordinates.
As for testing the correctness of the algorithm, given the fix coordinate comparing with the centroid coordinate, what's the best way to predict the accuracy?
@lemmingapex

Input as cartesians?

Hi,

just to make sure, I assume TrilaterationFunction expects the position argument to be in cartesian coordinates, not in lat/lon or anything else?

Cheers,
Julian

Odd behaviour when "triangulating" using two beacons.

Hello. Thank you for your enormous work.

I'm sorry if this sounds dumb, I've managed to get your library working and when I call your function NonLinearLeastSquaresSolver() and feed it the positions and the distances values, it outputs the centroid coordinates as it's supposed to do.
What looks suspicious to me is that given two beacons, the output centroid seems to be closer to the beacon that has the biggest distance from the phone.

For example, if the input values for the position of the beacons are (810,960) and (810,1440) and the distance values are 22 and 2 respectively, the output of the function is (810,1048), and that's closer to the beacon that had the bigger distance (22).

Am I missing something?

Thank you in advance.

Packaged JAR file for Processing

Thanks for this amazing library. I was able to get good results with trilateration from UWB DWM1000 modules. I was wondering how to compile this library as a Jar file to be included in Processing.

Taking a quick look at the gradle.settings, i ran "gradle sourcesJar" and ended up with a "trilateration-1.0.2-sources.jar" in the build/libs folder. Can i use this as a include/library in processing. Please let me know.

Incompatibles type LevenbergMarquardtOptimizer cannot be converted to LeastSquaresOptimizer NonLinearLeastSquaresSolver

Hello,
I am trying to implement your solution, but I am having a problem, here is the error that I have :

incompatible types: LevenbergMarquardtOptimizer cannot be converted to LeastSquaresOptimizer
	NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(new TrilaterationFunction(positions, distances), new LevenbergMarquardtOptimizer());

I really don't know why I am having this error, if I am doing something wrong, or if there is a type problem in the plugin.
Let me know if you have any idea.

Thanks for your work, if I can make it work it would be amazing!
Best regards.

Getting error rate

How do you get the error rate from the RealVector variable? In distance form?

// error and geometry information; may throw SingularMatrixException depending the threshold argument provided

RealVector standardDeviation = optimum.getSigma(0);
RealMatrix covarianceMatrix = optimum.getCovariances(0);

Port to C

Hi @lemmingapex, I need to use this in C. I checked to see whether I can port it to C but I couldn't find the functions you use with "commons-math". What I saw is only the interface for LeastSquaresOptimizer. Can you please provide link for the functions you used in the project?

Great work. Thank you very much.

Unexpected results

Hi there:

here is my data
double[][] positions = {{2,4},{21,13},{0,42}};
double [] distances = {35,45,5};

result [-19,31]

It seems way off, if you plot it , it should be around the [5,35] area.

Can you please tell me what is wrong?

Thanks

Java 1.7 compatibility problem

Hi,
I wanted to add your project into my android stodio project using gradle but I faced this error

Error:Error converting bytecode to dex: Cause: Dex cannot parse version 52 byte code. This is caused by library dependencies that have been compiled using Java 8 or above. If you are using the 'java' gradle plugin in a library submodule add targetCompatibility = '1.7' sourceCompatibility = '1.7' to that submodule's build.gradle file.

Is there any solutions to fix it?

3-Dimension Support?

Hi,

I'm wondering that this trilateration is support 3dimension? I tried with the below sample, but the result wasn't as I expected.

position points P1(1,1,1), P2(1,-1,1), P3(-1,-1,1) and the distances sqrt(3) to find location point P4(0,0,0) but the result was P4(-0.299678083,0.299678083, 1).

Excepted output of the example

I've managed to execute the example that you've given in the Readme section. But Im not able to understand the output that ive got. Please make me clear on this. I've posted a question about this in stackoverflow. Hope you could give me a right solution there. I dont know how to reach you thats why ive raised as a issue here.

How to use it in R³ localization?

I want to do some localizations in real spaces through iBeacon devices, and have successfully imported your dependency.
But the sample codes only show how to reach the answer in R² space
so how to use it in R³ space ?

Trilateration package with DWM1000

Hi,

I am trying to use your library in Processing(processing.org) for doing trilateration of a tag. The setup uses 3 Anchors and 1 Tag using dwm1000 modules and ESP.

I am getting the two way ranging distance of each anchor with the tag and passing it to Processing to do localization.

The two way ranging data has distance from the anchor, and signal strength. Now how do I pass these values to the trilateration package?

Are there any examples? If I can get this to work, I can contribute a Processing interface to visualise the trilateration data.

Thanks

Is "weighted" nonlinear least squares fitting possible?

Hi,

The library is working pretty well and giving good consistent results for me, great work!

Although I wanted to inquire if I can provide weights depending on the distance of the node to be positioned from the static nodes. The logic being the farther the range the more error will be there in the distance measured, is this already being done or can you suggest a modification which could facilitate that.

Thanks

which is better for residuals define?

in TrilaterationFunction , the value function calculate residuals.
it use d^2-r^2 as residuals
resultPoint[i] -= (this.getDistances()[i]) * (this.getDistances()[i]);

we also can use (d-r) as residuals

which is better ? @lemmingapex

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.