Equation to find the degrees of rotation of a once horizontal line
hey so I have a center of an object and i'm making a line with this center as the start of it, and the mouse position the end of it.
How do I find how rotated the second point (?,?) is around the stationary first point (0,0) ?
Note: if the second po开发者_Go百科int were (1, 0) it would be roated 0 degrees.Remember SOHCAHTOA? ;) You can use the arctangent (via the standard atan2()
function) to determine the angle of the line between the origin and an arbitrary point:
#include <cmath>
double mouseX = ...;
double mouseY = ...;
double angleInRadians = std::atan2(mouseY, mouseX);
If the angle of rotation is a
, and the second point is (x,y)
then:
a = arctan(y/x)
精彩评论