Angle between two points of lat-lon (cheat-sheet)

I could brute-force this, by dragging up 30-year old maths lessons, but maybe someone knows the answer quickly and easily.

What calculation do I need to get the angle of

  1. a right-angle triangle
  2. with its base on a line of latitude, and
  3. the hypotenuse lying between two known points of lat - lon?

Thanks :slight_smile:

1 Like

I’m afraid I don’t have the answer, but because the world isn’t flat I’m not sure this is easy. The longer the hypotenuse, the more important the non-flatness becomes.

Thanks.

I think that’s been helpfully dealt with here:

1 Like

I was just going to suggest here as you’ll know a and b as the differences in latitude and longitude.

Thanks, that looks useful.

What do the straight lines over the letters indicate? Feels like “side A” or “angle A” but I can’t tell which. If either of those.

It explains the notation to the left of the diagrams, so A with a line over it is 90 degrees - angle A (the complimentary angle). I don’t understand it when used with c, and it occurs to me we’ve only changed the issue from “the Earth isn’t flat” to “the Earth isn’t a sphere either”.

1 Like

:grin:

I think for my purposes it’ll be close enough - I only need relative positions, so if the baseline is out, and the data is out by the same degree, it should be ok.

I might as well describe the use-case: I have a csv of many points in the UK, and I want an approximate Scottish border to check which side of it they fall. So I’m calculating the angle from the latitude at Gretna* to Berwick, so for every point I can know if it’s north or south of that line.

The further away, the greater the non-sphere effect; but simultaneously the imprecision is less significant.

I think.

PS Maybe on that scale (heck, I could cycle it in a day), I can assume a flat plane?

'* Actually Parton, then the latitude west of the datum doesn’t cut the Stranraer peninsula. I’ll just have to manually check the Solway coast.

If I understand correctly, you want to find out if a point in your list lies within Scotland?
Perhaps you might want to turn the Scottish border into one or more polygons and then use something like GitHub - hayeswise/Leaflet.PointInPolygon: Point-in-polygon functions based on Dan Sunday's C++winding number implementation. to check whether a point is within that polygon.

Correct. Thanks for the suggestion: I’m flattered (as a person who can’t do basic trigonometry) that you think I know the top of a GitHub page from the bottom. :wink:

I’m using LO Calc as the summit of my technical abilities. Thankfully there are few enough points, and mostly in cities, that these very approximate polygons are good enough.

1 Like

Yeah, this question striked me as an XY problem - Wikipedia, so I provided a proper solution in case someone else gets the same idea :grin:

Of course, if that’s beyond what you are willing to invest (which is fair), then using the approximations here is fine.

1 Like

If you’re happy to approximate the border by a single straight line, then you might as well make that a straight line in latitude-longitude coordinates. Suppose you have two points on the line with (lat,lon) coordinates (x1,y1) and (x2,y2). then the equation of the line is

(y-y1)/(y2-y1) = (x-x1)/(x2-x1)

So for any given point (x,y) you can tell which side of the line it lies by looking at which of those two expressions is larger. If you have to test lots of points, then for efficiency you could first compute m=(y2-y1)/(x2-x1) once, and then compare y with m*(x-x1) + y1.

This is great, thank you: will do the job very well, I think.

I’ll post the Calc formulas once I’ve got it all sorted, in case it’s useful to anyone.