我有两个位置(纬度,经度),一个是当前位置,另一个是目标。我想要做的是有一个循环,将当前位置分阶段移动到目标位置。我并不完全确定将当前位置送到目标位置的数学。
答案 0 :(得分: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);
}
}