[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 573
  • Last Modified:

How can i calculate the angle between 2 vectors lat long?


x: lat, long
a: -95.77071229704562,34.9343240443434
b: -95.76835645203101,34.9339768366878
c: -95.774587384548,34.9259077248493

vector A is ba
vector B is bc

I have the distance in km of both vectors

A 0.218 km
B 1.062 km


thanks

Richard
0
verintsupport
Asked:
verintsupport
  • 2
1 Solution
 
AGBrownCommented:
You use the dot product of the two vectors, this gives the cosine of the angle between them by projecting the first vector onto the second:
A(dot)B = mod(A) x mod(B) x cos(angle)

Where:
A = ax+by = (a, b)
B = mx+ny = (m, n)
And so:
A(dot)B = am + bn
mod(A) = sqrt(a^2 + b^2)
mod(B) = sqrt(m^2 + n^2)

Therefore:
angle = cos<sup>-1</sup>((am + bn) / (sqrt(a^2 + b^2) * sqrt(m^2 + n^2))

And you can work out your vectors from (restarting the notation usage!):
a: (m, n)
b: (o, p)
c: (q, r)

A = ba = (m - o, n - p)
B = bc = (q - o, r - p)

Sorry for the horrendous notation: its impossible to write vector math on the web!

Andy
0
 
AGBrownCommented:
PS. I'm guessing that this is for some kind of GPS work? In which case, you can't truly approximate lat and long on a 2D plane without enormous errors unless points are _very_ close together. Surface of a sphere is a 1st order approximation, but one that gives errors over larger distances, an ellipsoid is better still.

Just found a reference for the dot products and angles between two vectors which might help clear up any notation problems from above (like the attempted superscript on the cos-1):
http://www.ltcconline.net/greenl/courses/107/Vectors/DOTCROS.HTM

Another online tool for computing the angle:
http://www.hpcsoft.com/products/MathSoL/vector/vectorAngle.html
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now