Answer the question
In order to leave comments, you need to log in
Can't translate from Delphi to C#
I would be very grateful if you could help me translate!
var
// Transmitted latitude/longitude in degrees and hundredths
StartLat: double; // Initial latitude
StartLong: double; // Initial longitude
EndLat: double; // End latitude
EndLong: double; // End longitude
// Variables used to calculate offset and distance
fPhimean: Double; // Average latitude
fdLambda: Double; // Difference between two longitude values
fdPhi: Double; // Difference between two latitude values
fAlpha: Double; // Offset
fRho: Double; // Meridian radius of curvature
fNu: Double; // Transverse radius of curvature
fR: Double; // Earth sphere radius
fz: Double; // Angular distance from the center of the spheroid
fTemp: Double; // Temporary variable used in calculations
Distance: Double; // Calculated distance in meters
Bearing: Double; // Calculated from and to offset
end
const
// Constants used to calculate offset and distance
D2R: Double = 0.017453; // Constant to convert degrees to radians
R2D: Double = 57.295781; // Constant to convert radians to degrees
a: Double = 6378137.0; // Main axles
b: Double = 6356752.314245; // Minor semiaxes
e2: Double = 0.006739496742337; // Square of the eccentricity of the ellipsoid
f: Double = 0.003352810664747; // Ellipsoid Alignment
begin
// Calculate the difference between two longitudes and latitudes and get the average latitude
fdLambda := (StartLong - EndLong) * D2R;
fdPhi := (StartLat - EndLat) * D2R;
fPhimean := ((StartLat + EndLat) / 2.0) * D2R;
// Calculate the meridian and transverse radii of curvature of the mid-latitude
fTemp := 1 - e2 * (Power(Sin(fPhimean), 2));
fRho := (a * (1 - e2)) / Power(fTemp, 1.5);
fNu := a / (Sqrt(1 - e2 * (Sin(fPhimean) * Sin(fPhimean))));
// Compute angular distance
fz :=
Sqrt(Power(Sin(fdPhi / 2.0), 2) + Cos(EndLat * D2R) * Cos(StartLat * D2R) *
Power(Sin(fdLambda / 2.0), 2));
fz := 2 * ArcSin(fz);
// Calculate offset
fAlpha := Cos(EndLat * D2R) * Sin(fdLambda) * 1 / Sin(fz);
fAlpha := ArcSin(fAlpha);
// Calculate the radius of the Earth
fR := (fRho * fNu) / ((fRho * Power(Sin(fAlpha), 2)) + (fNu *
Power(Cos(fAlpha), 2)));
// Get offset and distance
Distance := (fz * fR);
if ((StartLat < EndLat) and (StartLong < EndLong)) then
Bearing := Abs(fAlpha * R2D)
else if ((StartLat < EndLat) and (StartLong > EndLong)) then
Bearing := 360 - Abs(fAlpha * R2D )
else if ((StartLat > EndLat) and (StartLong > EndLong)) then
Bearing := 180 + Abs(fAlpha * R2D)
else if ((StartLat > EndLat) and (StartLong < EndLong)) then
Bearing := 180 - Abs(fAlpha * R2D);
end;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question