Solved

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

Posted on 2006-05-02
544 Views

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
Question by:verintsupport

LVL 12

Accepted Solution

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

LVL 12

Expert Comment

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

### Suggested Solutions

Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…