将 Point2D.Double x 距离移近另一个 Point2D.Double 的最佳方法是什么?
编辑:试图编辑,但因维护而停机。不,这不是作业
我需要将飞机 (A) 移向跑道 (C) 的尽头,并将其指向正确的方向(角度 a)。
替代文字 http://img246.imageshack.us/img246/9707/planec.png
这是我到目前为止所拥有的,但看起来很乱,做这样的事情的通常方法是什么?
//coordinate = plane coordinate (Point2D.Double)
//Distance = max distance the plane can travel in this frame
Triangle triangle = new Triangle(coordinate, new Coordinate(coordinate.x, landingCoordinate.y), landingCoordinate);
double angle = 0;
//Above to the left
if (coordinate.x <= landingCoordinate.x && coordinate.y <= landingCoordinate.y)
{
angle = triangle.getAngleC();
coordinate.rotate(angle, distance);
angle = (Math.PI-angle);
}
//Above to the right
else if (coordinate.x >= landingCoordinate.x && coordinate.y <= landingCoordinate.y)
{
angle = triangle.getAngleC();
coordinate.rotate(Math.PI-angle, distance);
angle = (Math.PI*1.5-angle);
}
plane.setAngle(angle);
三角形类可以在http://pastebin.com/RtCB2kSZ找到
记住飞机可以在跑道点周围的任何位置