有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java每秒查找位置

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

随机航路点模型为

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

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

我得到,以1米/秒的速度,从1,0到2,2需要2.4秒

但是,我需要在每一秒找到位置。我知道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) 个答案

  1. # 1 楼答案

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

    它以恒定速度从(x1,y1)(x2,y2),需要V秒,并且您希望在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), 
    

    因此,根据这个函数,{}之间的距离是sqrt(1^2+2^2)=2.23*而不是2.4*。因此,请相应地计算我的答案而不是除以2.4除以2.23