Giter Site home page Giter Site logo

tbmsp / trilateration Goto Github PK

View Code? Open in Web Editor NEW
25.0 3.0 14.0 18 KB

Trilateration system using 3 latitude and longitude points, and 3 radius distances in PHP, C#, Java and Javascript

License: MIT License

C# 27.27% Java 27.05% PHP 26.24% JavaScript 14.12% HTML 5.32%
trilateration latitude longitude points triangulation maps coordinates

trilateration's Introduction

Trilateration

Trilateration system using 3 latitude and longitude points, and 3 radius distances in PHP, C#, Java and Javascript

Where can Trilateration and Triangulation be used in general?

  • Get the location of a device that sends signals to an antenna (GPS).
  • Get the location of any device connected to a Wi-Fi network.
  • Get the epicenter of seismic events (Earthquakes).

And several other uses, with this library so simple you can perform the calculation, of course, this library does not know the parameters and these have to apply to you.


Class parameters and functions

Point Class:

new Point(Latitude,Longitude,RadiusDistanceInKilometers);

Trilateration Class:

new Trilateration();

Trilateration Class: Functions

Compute(Point1,Point2,Point3);

PHP Version Example

<?php
require("Point.php");
require("Trilateration.php");
$p1=new Point(-19.6685,-69.1942,84);
$p2=new Point(-20.2705,-70.1311,114);
$p3=new Point(-20.5656,-70.1807,120);
$a=new Trilateration();
$b=$a->Compute($p1,$p2,$p3);
echo "LatLon: ".$b[0].", ".$b[1];
?>

Result

LatLon: -20.548034139289, -69.266174618331

C# Version Example

using System;

namespace net.TBMSP.Code.Trilateration{
  class Program{
    static void Main(string[] args){
      Point p1=new Point(-19.6685,-69.1942,84);
      Point p2=new Point(-20.2705,-70.1311,114);
      Point p3=new Point(-20.5656,-70.1807,120);
      double[] a=Trilateration.Compute(p1,p2,p3);
      Console.WriteLine("LatLon: "+a[0]+", "+a[1]);
    }
  }
}

Result

LatLon: -20.548034139289, -69.266174618331

Java Version Example

package net.TBMSP.Code.Trilateration;

public class Main{
  public static void main(String[] args){
    Point p1=new Point(-19.6685,-69.1942,84);
    Point p2=new Point(-20.2705,-70.1311,114);
    Point p3=new Point(-20.5656,-70.1807,120);
    double[] a=Trilateration.Compute(p1,p2,p3);
    System.out.print("LatLon: "+a[0]+", "+a[1]);
  }
}

Result

LatLon: -20.548034139289, -69.266174618331

Javascript Version Example

<!DOCTYPE html>
<html>
  <body>
    <p id="latlon"></p>
    <script src="Trilateration.js"></script> 
    <script>
      //Array[Latitude,Longitude,RadiusDistanceInKilometers]
      var p1=[-19.6685,-69.1942,84];
      var p2=[-20.2705,-70.1311,114];
      var p3=[-20.5656,-70.1807,120];
      var a=Compute(p1,p2,p3);
      document.getElementById("latlon").innerHTML="LatLon: "+a;
    </script>
  </body>
</html>

Result

LatLon: -20.548034139289, -69.266174618331

Autor: @TBMSP TBM SP [email protected]

trilateration's People

Contributors

markettes avatar tbmsp 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

Watchers

 avatar  avatar  avatar

trilateration's Issues

Calculates incorrect location in javascript

Given these locations and distances:

51.619775, -3.940815, 214.04222
51.713638, -0.454319, 243.01033999999999
53.802161, -1.548517, 91.73238

The result given is 55.29375864900614, -3.6242426862571566 when it should be 53.398152,-2.751725

More than 3 points

Hi.

What if I have more than 3 coordinates? Can this algorithm be improved to support more points for more accuracy?

Problema con distancias cortas

Hola, estuve probando y mirando su código en la versión de javascript, y en mi caso tengo distancias de menos de un kilómetro, y el mensaje de error dice que la variable i tiene valor null. Mirando el código se hace una comparación de la distancia del primer punto contra un valor K que si es mayor asigna null a i.

Yo supongo que hay un problema con distancias cortas, que opina al respecto.

Buen día

calculates incorrect location in PHP

Given these coordinates and distances:
44.3657725000 -93.5890227000 72.97632697
44.8248516000 -93.4275748000 21.539728428
44.8598510000 -93.4920747000 22.393805166

the output is this:
LatLon: 44.555611619985, -93.572440674408

when it should be this:

44.953 , -93.3116

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.