我正在尝试编写一种方法,允许我的角斗士旋转两者之间的中心点,以便相互圈出。以下是我的代码。角斗士变量目标是角斗士类型,并在旋转中设置为第二方。 center [0]是x位置,center [1]是y。
public void rotate(Gladiator a, int angle) {
double x1;
double y1;
double x2;
double y2;
double r;
double midx;
double midy;
int currentAngle2;
int currentAngle;
r = getDistance(a,a.target)/2;
midx = (a.center[0]-a.target.center[0])/2;
midy = (a.center[1]-a.target.center[1])/2;
currentAngle = (int)Math.atan2(a.center[1] - midy, a.center[0] - midx);
currentAngle2 = currentAngle + 180;
if (currentAngle2 > 360) {
currentAngle2 = currentAngle2-360;
}
System.out.println("Current angles = "+currentAngle+","+currentAngle2);
x1 = Math.cos(currentAngle+angle) * r + midx;
y1 = Math.sin(currentAngle+angle) * r + midy;
x2 = Math.cos(currentAngle2+angle) * r + midx;
y2 = Math.sin(currentAngle2+angle) * r + midy;
System.out.println("new coords: "+(int)x1+","+(int)y1+","+(int)x2+","+(int)y2);
a.move((int)x1,(int)y1);
a.target.move((int)x2,(int)y2);
}
这是什么问题?第一次运行时,它们最终会相互叠加。
编辑:
angle是请求的旋转量。