Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to get the degree of a vector?

I am trying to claculate the angle of vectors in degrees. But I don't know where the origin of coordinates is in case of calculating the angle. So far, I use something like this:

degree = 180*(atan2(vector.back().y - vector.front().y, vector.back().x - vector.front().x))/M_PI

But the result is always positive, even if the x or y values are decreasing.

My questions are:

  • Where is the origin and orientation of the angular 2D plane? Is it top left corner?
  • How can I correctly calculate the angle of a vector?