Get the angle from a set of 3 2D coordinates?

26 Views Asked by At

I was wondering how i would get the angle from a set of coordinates (x,y). I mean the inside angle that makes a triangle.

For example, the points would be (2,5),(3,4), and (5,1)?

I am trying to think of a general approach as I want to program it.

As a side note, I am actually programming a navigation app that shows a user a top down map and calculates a route for the user to follow. I am taking coordinates from the route and trying to figure out when to tell the user to turn right or left. I figured I just need to figure out the angle of the coordinate the user is near and if its concave or convex....

1

There are 1 best solutions below

0
On

The standard way to do this is to use dot product. For any vectors $u,v \in \mathbb{R}^n$, the angle $\theta$ in between is given by $$ \cos\theta = \frac{u \cdot v}{\lVert u \rVert \lVert v \rVert} $$ where $\lVert u \rVert$ is the Euclidean length of $u$.

In your case, you can let $a = [2,5], b = [3,4], c = [5,1]$. Then $u$ and $v$ are given by $u = a - b, v = c - b$.