How to get the degree of a vector? [closed]
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?
Do you understand the concept of slope and angle, and how tan converts an angle into a slope, and atan converts a slope into an angle?
If you want the angle of a vector, you will always have to do it compared to the reference system you are using at that moment. If you use the OpenCV reference system, it is in the top left corner. Calculating the angle of the vector is basically calculating the angle of a line, based on the begin and end point, which you can do with the common formulas on tan and atan functionality.