|
Avr
12
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | procedure getCenter(dFromLatitude, dFromLongitude, dToLatitude, dToLongitude: Double; var dLatitude, dLongitude: Double); var dX, dY, dZ : Double; dN : Double; function ArcSinWithZero(dValue: Double): Double; var dCheck: Double; begin dCheck := sqrt(1-(dValue*dValue)); if (dCheck = 0) then dCheck := 0.0000000001; Result := ArcTan(dValue / dCheck); end; function CosWithoutZero(dValue: Double): Double; begin Result := Cos(dValue); if (Result = 0) then Result := 0.0000000001; end; begin // http://www.les-mathematiques.net/phorum/read.php?8,662153 // Converion en radian dFromLatitude := dFromLatitude / 180 * Pi; dFromLongitude := dFromLongitude / 180 * Pi; dToLatitude := dToLatitude / 180 * Pi; dToLongitude := dToLongitude / 180 * Pi; // Calcul de la résultante des deux positions dX := ( Cos(dFromLatitude) * Cos(dFromLongitude) ) + ( Cos(dToLatitude) * Cos(dToLongitude) ); dY := ( Cos(dFromLatitude) * Sin(dFromLongitude) ) + ( Cos(dToLatitude) * Sin(dToLongitude) ); dZ := ( Sin(dFromLatitude) + Sin(dToLatitude) ); // Calcul de la longueur dN := Sqrt(dX*dX+dY*dY+dZ*dZ); if dN = 0 then begin // Si la distance est nulle, le centre est donc au même endroit dLatitude := dFromLatitude; dLongitude := dFromLongitude; end else begin // Latitude dLatitude := ArcSinWithZero(dZ / dN); // Longitude if (dX < 0) then begin dLongitude := Sign(dY) * ( Pi - ArcSinWithZero( ( Abs(dY) / dN ) / CosWithoutZero( ArcSinWithZero(dZ / dN) ) ) ); end else begin dLongitude := ArcSinWithZero( (dY / dN) / CosWithoutZero( ArcSinWithZero(dZ / dN) ) ); end; end; // Conversion en degrés dLatitude := dLatitude * 180 / Pi; dLongitude := dLongitude * 180 / Pi; end; |
Pages : 1 2



Derniers commentaires