Berechnen Sie die Fläche eines Polygons mit Breiten- und Längengrad
Ich habe diesen Code, der folgendermaßen geschrieben wurde: source1 und das:quelle 2
public static double CalculatePolygonArea(IList<GpsLocation> coordinates)
{
double area = 0;
if (coordinates.Count > 2)
{
for (var i = 0; i < coordinates.Count-1; i++)
{
GpsLocation p1, p2;
p1 = coordinates[i];
p2 = coordinates[i + 1];
area += ToRad(p2.Longitude - p1.Longitude) * (2 + Math.Sin(ToRad(p1.Latitude))
+ Math.Sin(ToRad(p2.Latitude)));
area = area * R * R / 2;
}
}
return Math.Abs(area);
}
Hier ist mein Testcode:
[Fact]
public void GpsPolygonAreaTest()
{
var poly = new List<GpsLocation>();
var p1 = new GpsLocation(0, 0);
poly.Add(p1);
var p2 = GpsHelper.CreateLocationBasedOnBearingDistance(p1, 5, 100);
poly.Add(p2);
var p3 = GpsHelper.CreateLocationBasedOnBearingDistance(p2, 95, 100);
poly.Add(p3);
var p4 = GpsHelper.CreateLocationBasedOnBearingDistance(p3, 185, 100);
poly.Add(p4);
poly.Add(p1);
var area = GpsHelper.CalculatePolygonArea(poly);
area.Should().Be(10000);
}
Ich habe bestätigt, dass mein Polygon 100 x 100 m groß ist, siehe Bild:
Mein Testergebnis lautet: Der erwartete Wert ist 10000, wurde jedoch gefunden. 1.28153883377486E + 48.
Irgendwelche Ideen, was mit meinem Code nicht stimmt?