我正在制作一些动画,其中有许多三角形物体在屏幕上移动。为了确保每个人都面临着旅行的方向,我需要以合适的角度旋转图像。查找表示从原点坐标移动方向的角度
我的问题是我的代码返回的角度不能准确地做到这一点。返回的值不会改变超过几度。
/**
* Accepts two grid positions are arguments. The current position
* of the object and the next grid position. Returns an angle representing
* the direction of travel from the current position towards the next position. By converting the Cartesian coordinates into polar coordinates.
*
*/
public void setAngle(Vector2d currentPos, Vector2d nextPos) {
Double delta_x = current.xPos - next.xPos;
Double delta_y = current.yPos - next.yPos;
Double theta = Math.atan2(delta_y, delta_x);
this.angle = theta;
}
Example:
|| current: 1031.1438073417544 , 268.3133503758045 || next: 1033.101761841174 , 269.0819944286846 || Angle: 0.0
|| current: 1033.1901579769194 , 242.19363555578593 || next: 1035.1281222295695 , 243.08778242413436 || Angle: 0.0
|| current: 1022.1577455080815 , 255.24422527831163 || next: 1024.0301966330894 , 256.19078788718997 || Angle: 0.0
你的问题是不可能的,没有看到一些代码来回答。请注意,Math trig函数以弧度为单位,但JavaFX旋转以度为单位。 –
我已添加代码。希望这可以帮助。 –
你知道,输出中当前的pos和next pos值是相同的吗? – Roland