获取点和原点之间的角度
这个问题可能之前已经回答过,如果可以的话,对不起. 我基本上需要获得从原点到点的角度. 因此,假设来源为(0,0),而我的目标点为(3,0).
This might have been answered before, sorry if it has. I basically need to get the angle from origin to point. So lets say Origin is (0, 0) and my target point is (3, 0).
3点= 90度
6点= 180度
9点= 270度
12点= 0度
不知何故,我要做一些数学魔术,发现角度为90度(顶部为0). 原点可能会有所不同,因此我需要一个带有两个参数的方法Origin和TargetPoint,它返回度数为double的角度.
Somehow, I gotta do some math magic, and find out that the angle is 90 degrees (Top is 0). The origin can vary, so I need a method with two parameters, Origin, and TargetPoint, which returns double Angle in Degrees.
是的,我意识到这看起来很简短且没有建设性,但是我做了 问题尽可能简单易懂.所有其他的 问题已关闭-.-
Yea, I realize this looks short and nonconstructive, but I made the question as simple and understandable as possible. All the other questions were closed -.-
谢谢
两个点A和B之间的向量为B-A =(B.x-A.x,B.y-A.y).可以使用点积或
The vector between two points A and B is B-A = (B.x-A.x, B.y-A.y). The angle between two vectors can be calculated with the dot product or atan2.
var vector2 = Target - Origin;
var vector1 = new Point(0, 1) // 12 o'clock == 0°, assuming that y goes from bottom to top
double angleInRadians = Math.Atan2(vector2.Y, vector2.X) - Math.Atan2(vector1.Y, vector1.X);
另请参见在矢量之间查找符号角