Skip to content

Bug in CalculateBearing in Sphere2DCalculator #8

@bjarkeandersen

Description

@bjarkeandersen

Bearings are calculated wrong. The right code should be as follows (according to this formular ):

private double CalculateBearing(Coordinate c1, Coordinate c2)
{
    double dLon = Math.Abs(c2.X - c1.X) * Math.PI / 180;

    double y = Math.Sin(dLon) * Math.Cos(c2.Y * Math.PI / 180);
    double x = Math.Cos(c1.Y * Math.PI / 180) * Math.Sin(c2.Y * Math.PI / 180) -
                    (Math.Sin(c1.Y * Math.PI / 180) * Math.Cos(c2.Y * Math.PI / 180) * Math.Cos(dLon));

    double bearing = Math.Atan2(y, x);

    return bearing;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions