Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angle between 3 vertices

Tags:

c++

c

algorithm

For example, GetAngle((0,0),(100,0),(100,100)) = 90. How could I find the angle between 3 2D Points.

like image 402
jmasterx Avatar asked Jun 16 '10 21:06

jmasterx


1 Answers

Given points A, B, and C, you want the angle between AB and AC? First compute the vectors AB and AC -- it's just the coordinates of B minus coordinates of A and likewise for AC. Take the dot product of the two vectors. This is just the product of the x coordinates plus the product of the y coordinates of the vectors. Divide this number by the length of AB, and again by the length of AC. This result is the cosine of the angle between the two vectors, so take the arccos() and you have it.

like image 126
Sean Owen Avatar answered Sep 27 '22 16:09

Sean Owen