如图所示,知道ab两个坐标,从a点移动到b点,求每单位时间运动到的坐标。
只是简单的只有Y轴移动速度v,不是xy同时移动的速度。
//k=(y2-y1)/(x1-x2)对应求斜率
if (this.k == 0) {
this.k = (this.targetPos.y - nowPos.y)/(this.targetPos.x - nowPos.x);
}
//公式y=kx+b 求B:b = y-kx
if (this.b == 0) {
this.b = this.targetPos.y - this.k*this.targetPos.x;
}
let newPosY = v*time; //Y坐标的移动直接是速度乘以时间
//反推,知道y求x:x=(y-b)/k
newPosX = (newPosY - this.b)/this.k;