在这里,我正在计算演员和触摸点之间的度数,并将这个度数作为旋转角度传递给演员。我希望演员应该指向手指触摸或手指拖动方向。(考虑我通过手指触摸和拖动在路上拉公共汽车)
float degrees = (float) ((Math.atan2(touchPoint.x - crocodile.position.x, -(touchPoint.y - crocodile.position.y)) * 180.0d / Math.PI));
其计算度数正确。只是有时在两者之间它给出了不同的程度。所以当结果真的与预期不同时,我的演员就会波动。
我打印的结果是:
块引用
degree is :: 141.93233
degree is :: 180.0
degree is :: 180.0
degree is :: 158.61426
degree is :: 90.0
degree is :: 180.0
degree is :: 180.0
degree is :: 90.0
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93057
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93306
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93257
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93134
degree is :: 141.93257
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93134
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93306
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93257
degree is :: 180.0
degree is :: 141.93134
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93257
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93257
degree is :: 180.0
degree is :: 141.93134
degree is :: 180.0
degree is :: 141.93257
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93008
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93306
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93257
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93134
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
现在,180 和 141 为什么会随着这些值波动。考虑到我一直期待 141 或 180 我需要在上述公式中进行更改。