开发者

Equation to find the degrees of rotation of a once horizontal line

开发者 https://www.devze.com 2023-04-02 04:11 出处:网络
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.

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消