【发布时间】:2012-06-20 20:55:04
【问题描述】:
我需要帮助以使下面的代码更高效,并对其进行一些清理。
如image 所示,x 和 y 可以是整个屏幕周围的任意点,我正在尝试找到角度 t。有什么办法可以减少这里的行数吗?
注意:原点在左上角,向右/向下移动是正向移动
o := MiddleOfScreenX - x;
a := MiddleOfScreenY - y;
t := Abs(Degrees(ArcTan(o / a)));
if(x > MiddleOfScreenX)then
begin
if(y > MiddleOfScreenY)then
t := 180 + t
else
t := 360 - t;
end
else
if(y > MiddleOfScreenY)then
t := 180 - t;
代码是帕斯卡,但用类似语法的其他语言或 c++ 或 java 的答案也可以。
:= sets the variable to that value
Abs() result is the absolute of that value (removes negatives)
Degrees() converts from radians to degrees
ArcTan() returns the inverse tan
【问题讨论】:
标签: java c++ pascal trigonometry