每秒寻找位置

时间:2014-03-26 02:31:53

标签: java

我正在尝试实施随机航路点模型。我对此有一点怀疑。 随机路点模型统计数据:

随机航点模型

最广泛使用的移动模型之一。在标准随机 航路点模型,每个节点选择一个随机位置作为目的地 并以随机选择的速度向目的地移动; 到达目的地后,节点暂停一些随机 时间量并选择一个新目的地并重复 过程

所以,我有一个问题。假设随机速度在0.3-2.5米/秒之间。我首先保留一个随机位置为1,0,下一个目的地为2,2。

所以,我得到它需要2.4秒从1,0到2,2,速度为1米/秒。

但是,我需要每秒都找到位置。我知道在2.4秒它是2,2,但我怎么知道在1秒结束时,会是什么位置。

更新:有一个解决方案并尝试过,但没有得到答案

I multiplied it with that vector only, but i am not getting any near answer. 


Suppose, I have co-ordinates as: 1,0 and 2,2. 



The distance between them is 2.8 m. 


It takes 2.8 sec for velocity 1 m/sec. Thus, If I want to find location at 1 sec, then I applied the formula as :



    LookLen = sqrt(2^2+1^2)

    Distance travelled from 1,0 to 2,2 is 2.4. Thus with velocity =1 m/sec, the time is 2.4 sec. Thus, for t= 1 sec, the distance travelled with same velocity would be 1 m/sec.

Now, calculating the normalized vector. (2,2)-(1,0) = (1,2).

Thus, multiplying with the distance to be travelled : 

(1,2) * 1= (1,2)

So, Is (1,2) the new location ??

1 个答案:

答案 0 :(得分:2)

如果我没有弄错并正确理解,那应该是这样的:

(x1,y1)(x2,y2)以恒定速度Vt_total秒,你想知道t_cur之后你的点位置秒

然后在一秒后,位置将是,

x_next = x1 + (x2-x1)/t_total*t_cur;
y_next = y1 + (y2-y1)/t_total*t_cur;

对于您的示例,它将是x_next = 1+1/2.4 = 1.41 & y_next = 0 + 2/2.4=0.81。 1秒后的位置是(1.41,0.81)。

然而,这是几何问题而非编程等。

更正:点之间的距离可以这样计算:

dist = sqrt((x2-x1)^2 + (y2-y1)^2), 

所以,根据这个函数,(1,0) and (2,2)之间的距离是 sqrt(1 ^ 2 + 2 ^ 2)= 2.23 * 而不是2.4 *。所以,相应地计算我的答案。 而不是划分为2.4除以2.23

相关问题