I need to calculate the target coordinate by using the initial coordinate, bearing angle and distance. I came across this on how to calculate it. Then I construct the code in C#, but it seems I can't get exact location correctly. I use below code this my answer:
Target latitude :6.34374176458679
Target longitude : 206.297566445544
When I use the application from the website i mention it get this:
Destination point: 03° 10′ 28″ N, 103° 08′ 15″ E /Lat:3.174444° Lon:103.150833°
Final bearing: 040° 24′ 37″
That are most accurate. Has anybody used this kind of method?
EDIT:
//bearing angle
double rad = 40.41;
rad *= Math.PI / 180;
//angDist = distance/radius
double angDist = 0.717 / 6371;
Console.WriteLine("Angular distance:" + angDist);
double latitude = 3.169416;
double longitude = 103.146690;
latitude *= Math.PI / 180;
longitude *= Math.PI / 180;
double lat2 = Math.Asin(Math.Sin(latitude)*Math.Cos(angDist)+Math.Cos(latitude)*Math.Sin(angDist)*Math.Cos(rad));
double forAtana = Math.Sin(rad) * Math.Sin(angDist) * Math.Cos(latitude);
double forAtanb = Math.Cos(angDist)-Math.Sin(latitude)*Math.Sin(lat2);
double lon2 = longitude + Math.Atan2(forAtana,forAtanb);
double finalLat = latitude + lat2;
double finalLon = longitude + lon2;
finalLat *= 180 / Math.PI;
finalLon *= 180 / Math.PI;
Console.WriteLine("Target latitude :" + finalLat);
Console.WriteLine("Target longitude : " + finalLon);
// supposely final answer should be Lat:3.174444° Lon:103.150833° (using the movable-type website)
Console.ReadKey();