Lakukan dalam bahasa PHP:
// mengasumsikan ketinggian = 0
$ earthR = 6371; // dalam km (= 3959 mil)
$ 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;
/ *
#menggunakan bola authalic
#Jika menggunakan ellipsoid, langkah ini sedikit berbeda
# Konversi geodetik Lat / Panjang ke ECEF xyz
# 1. Konversi Lat / Panjang ke radian
# 2. Konversi Lat / Panjang (radian) ke ECEF
* /
$ 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)));
/ *
MEMASANG:
sudo pear instal Math_Vector-0.7.0
sudo pear instal Math_Matrix-0.8.7
* /
// Sertakan PEAR :: Math_Matrix
// /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));
#dari wikipedia: http://en.wikipedia.org/wiki/Trilateration
#transformasi untuk mendapatkan lingkaran 1 di tempat asalnya
#transformasi untuk mendapatkan lingkaran 2 pada sumbu x
// CALC EX
$ P2minusP1 = Math_VectorOp :: subtract ($ P2vector, $ P1vector);
$ l = new Math_Vector ($ P2minusP1);
$ P2minusP1_length = $ l-> length ();
$ norm = new Math_Vector3 (array ($ P2minusP1_length, $ P2minusP1_length, $ P2minusP1_length));
$ d = $ norm; // simpan calc 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 :: subtract ($ 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 :: subtract ($ P3minusP1, $ iex);
// echo "P3P1iex =". $ P3P1iex-> toString (). "\ n";
$ l = new 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
// lakukan sebelumnya
$ d = floatval ($ d -> _ tuple-> getData () [0]);
// echo "d = $ d \ n";
// CALC J
$ j = Math_VectorOp :: dotProduct ($ ey, $ P3minusP1);
// echo "j = $ j \ n";
#dari wikipedia
# colok dan cabut menggunakan nilai di atas
$ 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);
# hanya satu kasing yang ditunjukkan di sini
$ z = sqrt (pow ($ DistA, 2) - pow ($ x, 2) - pow ($ y, 2));
// echo "x = $ x - y = $ y - z = $ z \ n";
#triPt adalah array dengan ECEF x, y, z dari titik trilateration
$ xex = Math_VectorOp :: scale ($ x, $ ex);
$ yey = Math_VectorOp :: scale ($ y, $ ey);
$ zez = Math_VectorOp :: scale ($ z, $ ez);
// CALC $ triPt = $ P1vektor + $ 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]);
#convert kembali ke lat / long dari ECEF
#konversi ke derajat
$ lat = rad2deg (asin ($ triPt_z / $ earthR));
$ lon = rad2deg (atan2 ($ triPt_y, $ triPt_x));
echo $ lat. ','. $ lon;