-2

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

Community
  • 1
  • 1

1 Answers1

2
#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.

Jashaszun
  • 9,207
  • 3
  • 29
  • 57