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 6819547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:19:10+00:00 2026-05-26T21:19:10+00:00

I expected this to be simple, but I’m getting some strange results. I’d appreciate

  • 0

I expected this to be simple, but I’m getting some strange results. I’d appreciate if someone could point out what I’m doing wrong.

I have 3 points (A, B, C) defined on the surface of the Earth (assumed to be a sphere) with [lat, long] coordinates for each point. I need to calculate the angle between the two Great Arcs formed by AC and AB.

I already have a function that calculates the Great Circle Distance (GCD), so I decided to solve this problem by getting the GCD for AC, AB and CA, reducing them to a unit sphere and then applying the Spherical Law of Cosines to get at the angle BAC.

This appeared to work and gave me reasonable angles. However, I then tried to put all three points on the same Great Circle and a strange thing started happening. If B and C were within 1 degree, the results were reasonable, but as I started moving B and C further apart along the same Great Circle, the angle started growing!

For example:

A = 49, 1
B = 49, 10     => Angle: 0.0378
C = 49, 10.1

A = 49, 1
B = 49, 10     => Angle: 0.2270
C = 49, 10.6

A = 49, 1
B = 49, 10     => Angle: 3.7988
C = 49, 20

A = 49, 1
B = 49, 10     => Angle: 99.1027
C = 49, 200

Is this some sort of precision error, or is my formula wrong?

Here is the code (getDistance() is known to work):

  public static BigDecimal getAngle(
      final BigDecimal commonLat, final BigDecimal commonLong,
      final BigDecimal p1Lat, final BigDecimal p1Long,
      final BigDecimal p2Lat, final BigDecimal p2Long) {

    // Convert real distances to unit sphere distances
    //
    double a = getDistance(p1Lat, p1Long, commonLat, commonLong).doubleValue() / RADIUS_EARTH;
    double b = getDistance(p2Lat, p2Long, commonLat, commonLong).doubleValue() / RADIUS_EARTH;
    double c = getDistance(p1Lat, p1Long, p2Lat, p2Long).doubleValue() / RADIUS_EARTH;

    // Use the Spherical law of cosines to get at the angle between a and b
    //
    double numerator = Math.cos(c) - Math.cos(a) * Math.cos(b);
    double denominator = Math.sin(a) * Math.sin(b);
    double theta = Math.acos(numerator / denominator);

    // Back to degrees
    //
    double angleInDegrees = Math.toDegrees(theta);

    return new BigDecimal(angleInDegrees);
  }

Unfortunately for me, my application will often have points nearly on a line, so accuracy in this situation is important. What is going wrong here?

EDIT: As requested, here is the code for getDistance():

public static BigDecimal getDistance(final BigDecimal endLat, final BigDecimal endLong, 
    final BigDecimal startLat, final BigDecimal startLong) {

  final double latDiff = Math.toRadians(endLat.doubleValue() - startLat.doubleValue());
  final double longDiff = Math.toRadians(endLong.doubleValue() - startLong.doubleValue());

  final double lat1 = Math.toRadians(startLat.doubleValue());
  final double lat2 = Math.toRadians(endLat.doubleValue());

  double a =
      Math.sin(latDiff / 2) * Math.sin(latDiff / 2) + 
      Math.sin(longDiff / 2) * Math.sin(longDiff / 2) * Math.cos(lat1) * Math.cos(lat2);
  double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  double d = RADIUS_EARTH * c;

  return new BigDecimal(d);
}

The declaration of RADIUS_EARTH is irrelevant, b/c we multiply by it in distance calculation and then divide by it in angle calculation, so it is cancelled out.

  • 1 1 Answer
  • 0 Views
  • 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-26T21:19:11+00:00Added an answer on May 26, 2026 at 9:19 pm

    A quick look on your coordinates say, that the latitude ist the same and longitude varies. But all circles made by latitude (except equator) aren’t great circles. Did you try your program, if longitude is constant and latitude is varied?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I expected this to be a simple task, but I'm surprised to find no
I am attempting to interop to this simple scala code, but am having some
please try out this simple page: http://www.ynnova.it/ie9bug/tryit.html I use jquery 1.7.1 but I think
I can not figure out what is going wrong but on this simple PHP
I expected this to compile, but I kept getting the error The type of
This should be really simple but for some reason I'm stumped on this... I'm
This seems like it should be simple but I can't work it out from
[purpose] This simple command sequence runs expected in the Windows' CMD shell: dir &
I expected this to print [b] but it prints [] : $x = abc;
I am getting this error While running this LoadError: Expected /home/user/Desktop/Tripurari/myapp/app/models/host.rb to define Host##

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.