【发布时间】:2014-09-27 16:18:21
【问题描述】:
我需要计算两点之间的角度,用一条线与给定的两点相连的固定点。
这是一张说明我需要的图片:
这是我迄今为止尝试过的:
public static float GetAngleOfLineBetweenTwoPoints(float x1, float x2, float y1, float y2) {
float xDiff = x2 - x1;
float yDiff = y2 - y1;
return (float) (Math.atan2(yDiff, xDiff) * (180 / Math.PI));
}
说它没有提供正确的答案是没有意义的。
【问题讨论】:
-
你现在连“原点”的坐标都没有考虑吧?
-
你的固定点是什么?你也需要那个点
-
添加第三个点(如@getlost 所述)并使用矢量角度公式:vitutor.com/geometry/vec/angle_vectors.html
-
来自@RomeoKienzler 的帖子(因为这不是答案),您应该查看以下内容:How to calculate the angle between a line and the horizontal axis?