J'ai une méthode qui est supposée calculer le relèvement entre deux coordonnées géographiques (en format d'exemple 40.7486, -73.9864).Sortie bizarre dans le relèvement entre deux calculs de coordonnées
Je rencontre cependant un problème lorsque le cap qu'il calcule est différent du titre que je calcule en utilisant une application éprouvée.
Par exemple, le roulement initial entre des points suivants est 074 degrés, mais ma méthode retourne 047.
40.7486, -73.9864
40.9486, -72.9866
Voici la snippit pertinente du code.
/// <summary>
/// Calculate the inital bearing between two Locations
/// </summary>
/// <param name="pointA"></param>
/// <param name="pointB"></param>
/// <param name="headingType"></param>
/// <returns></returns>
public static double BearingToLocation(Location pointA, Location pointB)
{
// Convert both locations from degrees to radians
pointA = LocationToRad(pointA);
pointB = LocationToRad(pointB);
double partOne = exMath.Sin(pointB.Longitude - pointA.Longitude) * exMath.Cos(pointB.Latitude);
double partTwo = exMath.Cos(pointA.Latitude) * exMath.Sin(pointB.Latitude) - exMath.Sin(pointA.Latitude) * exMath.Cos(pointB.Latitude) * exMath.Cos(pointB.Longitude - pointA.Longitude);
double heading = AdditionalMath.ToDeg(exMath.Atan2(partOne, partTwo) % 2 * exMath.PI);
// Solve for compass wrap around
if (heading < 0)
heading += 360;
return heading;
}
/// <summary>
/// Return a new location in radians
/// </summary>
/// <param name="pointA"></param>
/// <returns></returns>
public static Location LocationToRad(Location pointA)
{
return new Location(AdditionalMath.ToRad(pointA.Latitude), AdditionalMath.ToRad(pointA.Longitude), pointA.Altitude);
}
}
/// <summary>
/// Misc. math functions not available in Elze Kool's lib
/// </summary>
public static class AdditionalMath
{
/// <summary>
/// Degrees to radians
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public static double ToRad(double x)
{
return exMath.PI * x/180.00F;
}
/// <summary>
/// Radians to degrees
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public static double ToDeg(double x)
{
return x * 180.00F/exMath.PI;
}
}
Quelqu'un peut-il voir le problème? Je l'ai regardé et n'ai pas pu trouver le problème.
Ce qui a fini par être la solution? Code utile ... – Brandon
C'était en fait la bibliothèque de maths. L'original que j'ai utilisé a été écrit par Elze Kool, et il y avait plusieurs problèmes. À la fin, je l'ai mis au rebut et utilisé celui qui a été mis en place la nativité sur mon appareil (GHI Electronics FEZ Domino) – chris12892