我有两个位置(纬度、经度),一个是当前位置,另一个是目标。我想做的是有一个循环,将当前位置分阶段移动到目标位置。我不完全确定将当前位置转移到目标位置的数学方法。
问问题
115 次
1 回答
1
这是在两点之间分阶段实现所有点的粗略演示代码。希望对您有所帮助:
import java.awt.Point;
public class Path
{
public static void main(String[] args)
{
Point start = new Point(0,0);
Point destination = new Point(100,150);
int iStages = 9;//Suppose I want to reach to destination in 9 jumps
int jumpX = (destination.x - start.x) / iStages;
int jumpY = (destination.y - start.y) / iStages;
Point currPos = start;
for (int i = 0; i < iStages ; i++)
{
System.out.println(currPos);
currPos = new Point(currPos.x + jumpX , currPos.y + jumpY );
}
currPos = new Point(destination.x , destination.y);
System.out.println(currPos);
}
}
于 2013-02-01T13:46:32.430 回答