Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3285356
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:15:29+00:00 2026-05-17T20:15:29+00:00

I have a method that that is suppose to calculate the bearing between two

  • 0

I have a method that that is suppose to calculate the bearing between two geographic coordinates (in 40.7486, -73.9864 example format).

I am however, having an issue where the heading that it calculates is different from the heading I calculate using a tried and tested application.

For example, the initial bearing between of the following points is 074 degrees, however my method returns 047.

40.7486, -73.9864

40.9486, -72.9866

Here is the relevant snippit of 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;
    }
}

Can anyone see the issue? I looked it over and could not find the issue.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:15:29+00:00Added an answer on May 17, 2026 at 8:15 pm

    The % looks fishy in this line:

        double heading = AdditionalMath.ToDeg(exMath.Atan2(partOne, partTwo) % 2 * exMath.PI);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Java, suppose I have a method that takes in two lists of integers,
Suppose I have a method that must return an object (say from a database
Suppose I have a Java method that returns a HashMap object. Because a LinkedHashMap
Suppose that we have a class called class1. The class1 has a method called
Suppose you have some method that could be made static, inside a non-static class.
Let's suppose I have some method that returns a IEnumerable<int> object. This methods make
Suppose we have a method that accepts a value of an enumeration. After this
Suppose I have a method that combines several address fields like so: def address
Suppose I have a method to calculate combinations of r items from n items:
I have a method that is suppose to edit a xml file: public void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.