Mach es in PHP Sprache:
// Unter der Annahme von Höhe = 0
$ earthR = 6371; // in km (= 3959 in Meilen)
$ LatA = 37.418436;
$ LonA = -121,963477;
$ DistA = 0,265710701754;
$ LatB = 37.417243;
$ LonB = -121.961889;
$ DistB = 0,234592423446;
$ LatC = 37.418692;
$ LonC = -121.960194;
$ DistC = 0,0548954278262;
/ *
# unter Verwendung der authalen Kugel
#wenn ein Ellipsoid verwendet wird, unterscheidet sich dieser Schritt geringfügig
#Geodätisches Lat / Long in ECEF xyz konvertieren
# 1. Lat / Long in Radiant umrechnen
# 2. Lat / Long (Bogenmaß) in ECEF umrechnen
* /
$ xA = $ earthR * (cos (deg2rad ($ LatA)) * cos (deg2rad ($ LonA)));
$ yA = $ earthR * (cos (deg2rad ($ LatA)) * sin (deg2rad ($ LonA)));
$ zA = $ earthR * (sin (deg2rad ($ LatA)));
$ xB = $ earthR * (cos (deg2rad ($ LatB)) * cos (deg2rad ($ LonB)));
$ yB = $ earthR * (cos (deg2rad ($ LatB)) * sin (deg2rad ($ LonB)));
$ zB = $ earthR * (sin (deg2rad ($ LatB)));
$ xC = $ earthR * (cos (deg2rad ($ LatC)) * cos (deg2rad ($ LonC)));
$ yC = $ earthR * (cos (deg2rad ($ LatC)) * sin (deg2rad ($ LonC)));
$ zC = $ earthR * (sin (deg2rad ($ LatC)));
/ *
INSTALLIEREN:
sudo pear installiert Math_Vector-0.7.0
sudo pear install Math_Matrix-0.8.7
* /
// PEAR :: Math_Matrix einbinden
// /usr/share/php/Math/Matrix.php
// include_path = ".: / usr / local / php / pear /"
require_once 'Math / Matrix.php';
require_once 'Math / Vector.php';
require_once 'Math / Vector3.php';
$ P1vector = new Math_Vector3 (Array ($ xA, $ yA, $ zA));
$ P2vector = new Math_Vector3 (Array ($ xB, $ yB, $ zB));
$ P3vector = new Math_Vector3 (Array ($ xC, $ yC, $ zC));
#aus Wikipedia: http://en.wikipedia.org/wiki/Trilateration
#transformiere, um Kreis 1 am Ursprung zu erhalten
#transformiere, um Kreis 2 auf der x-Achse zu erhalten
// CALC EX
$ P2minusP1 = Math_VectorOp :: substract ($ P2vector, $ P1vector);
$ l = neuer Math_Vector ($ P2minusP1);
$ P2minusP1_length = $ l-> length ();
$ norm = new Math_Vector3 (Array ($ P2minusP1_length, $ P2minusP1_length, $ P2minusP1_length));
$ d = $ norm; // Berechnung speichern D
$ ex = Math_VectorOp :: divide ($ P2minusP1, $ norm);
// echo "ex:". $ ex-> toString (). "\ n";
$ ex_x = floatval ($ ex -> _ tuple-> getData () [0]);
$ ex_y = floatval ($ ex -> _ tuple-> getData () [1]);
$ ex_z = floatval ($ ex -> _tuple-> getData () [2]);
$ ex = new Math_Vector3 (Array ($ ex_x, $ ex_y, $ ex_z));
// CALC i
$ P3minusP1 = Math_VectorOp :: substract ($ P3vector, $ P1vector);
$ P3minusP1_x = floatval ($ P3minusP1 -> _tuple-> getData () [0]);
$ P3minusP1_y = floatval ($ P3minusP1 -> _tuple-> getData () [1]);
$ P3minusP1_z = floatval ($ P3minusP1 -> _tuple-> getData () [2]);
$ P3minusP1 = new Math_Vector3 (Array ($ P3minusP1_x, $ P3minusP1_y, $ P3minusP1_z));
$ i = Math_VectorOp :: dotProduct ($ ex, $ P3minusP1);
// echo "i = $ i \ n";
// CALC EY
$ iex = Math_VectorOp :: scale ($ i, $ ex);
// echo "iex =". $ iex-> toString (). "\ n";
$ P3P1iex = Math_VectorOp :: substract ($ P3minusP1, $ iex);
// Echo "P3P1iex =". $ P3P1iex-> toString (). "\ n";
$ l = neuer Math_Vector ($ P3P1iex);
$ P3P1iex_length = $ l-> length ();
$ norm = new Math_Vector3 (Array ($ P3P1iex_length, $ P3P1iex_length, $ P3P1iex_length));
// echo "norm:". $ norm-> toString (). "\ n";
$ ey = Math_VectorOp :: divide ($ P3P1iex, $ norm);
// echo "ey =". $ ey-> toString (). "\ n";
$ ey_x = floatval ($ ey -> _ tuple-> getData () [0]);
$ ey_y = floatval ($ ey -> _ tuple-> getData () [1]);
$ ey_z = floatval ($ ey -> _tuple-> getData () [2]);
$ ey = new Math_Vector3 (Array ($ ey_x, $ ey_y, $ ey_z));
// CALC EZ
$ ez = Math_VectorOp :: crossProduct ($ ex, $ ey);
// echo "ez =". $ ez-> toString (). "\ n";
// CALC D
// mach es vorher
$ d = floatval ($ d -> _tuple-> getData () [0]);
// echo "d = $ d \ n";
// CALC J
$ j = Math_VectorOp :: dotProduct ($ ey, $ P3minusP1);
// echo "j = $ j \ n";
#aus Wikipedia
#plug und chug mit den obigen Werten
$ x = (pow ($ DistA, 2) - pow ($ DistB, 2) + pow ($ d, 2)) / (2 * $ d);
$ y = ((pow ($ DistA, 2) - pow ($ DistC, 2) + pow ($ i, 2) + pow ($ j, 2)) / (2 * $ j)) - (($ i / $ j) * $ x);
# Hier wird nur ein Fall angezeigt
$ z = sqrt (pow ($ DistA, 2) - pow ($ x, 2) - pow ($ y, 2));
// echo "x = $ x - y = $ y - z = $ z \ n";
#triPt ist ein Array mit ECEF x, y, z des Trilaterationspunkts
$ xex = Math_VectorOp :: scale ($ x, $ ex);
$ yey = Math_VectorOp :: scale ($ y, $ ey);
$ zez = Math_VectorOp :: scale ($ z, $ ez);
// CALC $ triPt = $ P1vector + $ xex + $ yey + $ zez;
$ triPt = Math_VectorOp :: add ($ P1vector, $ xex);
$ triPt = Math_VectorOp :: add ($ triPt, $ yey);
$ triPt = Math_VectorOp :: add ($ triPt, $ zez);
// echo "triPt =". $ triPt-> toString (). "\ n";
$ triPt_x = floatval ($ triPt -> _ tuple-> getData () [0]);
$ triPt_y = floatval ($ triPt -> _ tuple-> getData () [1]);
$ triPt_z = floatval ($ triPt -> _ tuple-> getData () [2]);
# Von ECEF zurück nach Lat / Long konvertieren
#in Grad umrechnen
$ lat = rad2deg (asin ($ triPt_z / $ earthR));
$ lon = rad2deg (atan2 ($ triPt_y, $ triPt_x));
echo $ lat. ','. $ lon;