我需要帮助来模拟平面上两点之间的运动。考虑两个点 P1:(x,y1) 和 P2:(x2,y2)。我计算 P1 和 P2 之间的距离,例如 D,然后选择一个随机速度,例如 V。接下来,我计算从 P1 移动到 P2 所需的时间,例如 T。最后,我计算 P1 和 P2 之间的直线方程为 y = mx + b。
例如,令 T = 10 秒。在前 9 秒中,我想在直线上每秒生成点,直到第 10 秒到达点 P2。您能帮我这样做吗?
I need assistance in simulating movement between 2 points in a plane. Consider two points P1:(x,y1) and P2:(x2,y2). I compute the distance between P1 and P2, say D, and I choose a random velocity, say V. Next, I compute the time required to move from P1 to P2, say T. Finally, I compute the equation of the straight line between P1 and P2 as y = mx + b.
For example, let T = 10 seconds. For the first 9 seconds, I would like to generate points per second on the straight line until I reach point P2 at the 10th second. Could you please assist me in doing so.
发布评论
评论(1)
最好的方法是使用参数方程
,其中
t
是从 0 到 1 的“时间”参数(0.5 表示例如中间)。如果您还希望运动“柔和”(从零速度开始,然后加速,然后减速并在到达点停止),您可以使用这个修改后的方程。
以下是
w
的图与具有 11 个点的线性分布t
相比的曲线 (t=0.0, 0.1, ... 0.9, 1.0):The best approach is to use parametric equations
where
t
is the "time" parameter going from 0 to 1 (0.5 means for example halfway).If you also like your movement to be "soft" (starting from zero velocity, then accelerating then slowing down and stopping on the arrival point) you can use this modified equation
The following is a plot of the
w
curve compared to a linear distributiont
with 11 points (t=0.0, 0.1, ... 0.9, 1.0):