Calculating the closest point a line intersects with a circle on a world map?

55 Views Asked by At

I am working with the world map and trying to figure out an equation to solve:

  • Given starting point A which is latitude 51.137933 and longitude -0.267017, I want draw a straight line or head in the direction of bearing 257 degrees.
  • Given an ending point B, which is latitude 51.053953 and longitude -0.625003 (the center of the circle), imagine a 10.5 nautical mile radius around it.
  • I want the line from point A to go from there to the closest intersection point of the 10.5 nautical mile radius of point B and I want to know what latitude and longitude this position C is.
  • In this example the correct answer should output point C as a lat/lng close to 51.12297220241921 -0.37027234945405624 (although this may be 0.1 miles off).

The below diagram may help better explain (although slightly different example, same concept):

enter image description here

Forgive me, my maths is not so good as I am primarily a software engineer, so please do dumb down the mathematically terms to help me understand.

I have found that there are similar problems where figuring out whether a line intersects a circle is quite common, but I think this one is slightly different in that;

  • I am dealing with the world map, so we may have to account for the curvature of the earth.
  • I am only interested in the exact position of the first closest (to point A) intersection, not all intersection points or a simple yes / no whether it intersects.
  • Finally, the heading the line is drawn must be fixed to 257 degrees, I have seen some formulas which try to just find the best heading as well, but in this case the heading can't change and in some circumstances that means it will never hit the circle too.

I have actually programmed something that solves this problem, but it doesn't use an equation, instead it's quite inefficient as it brute forces the path until it reaches the circle, see here: https://stackoverflow.com/questions/76217015/how-to-calculate-the-first-point-where-a-line-intersects-a-circle-radius-on-a-ma/76217601#76217601

I realise this is more a math problem so posting my question here.