How to get the degree of a vector? [closed]

asked 2019-08-07 10:11:23 -0600

hg255 gravatar image

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?
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-11-17 14:00:29.376374

Comments

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?

sjhalayka gravatar imagesjhalayka ( 2019-08-07 12:17:44 -0600 )edit

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.

StevenPuttemans gravatar imageStevenPuttemans ( 2019-08-20 08:12:10 -0600 )edit