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

Posted on 2006-05-02
Last Modified: 2010-04-16

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


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)

    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)

    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!

    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):

    Another online tool for computing the angle:

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    Article by: Najam
    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…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now