Calculate The object angle(face) having two points?

572 views Asked by At

C++, I want calculate the angle of the direction of the two points.

Here is a picture which shows the two points and the direction of how to get the angle of the direction?

enter image description here

p1 - start point. p2 - direction point. me need direction angle(facing?) from p1 to p2

1

There are 1 answers

7
Jashaszun On BEST ANSWER
#include <cmath>

// ...
double angle = atan2(p2.y - p1.y, p2.x - p1.x);
// ...

If you want to, you can also make sure that p1 != p2, because if it is then you'll get a domain error.