我认为,您只是以错误的方式调用例程(可能会将其传递给整个粒子数组,而不是仅用于一个粒子的数组。
无论如何,另一种可能的解决方案是将您的阵列拆分为单独的阵列:
import numpy as np
pos = np.array([[200,0], [210,210], [215,215], [192,186]], dtype=float)
lastpos = np.array([[200,2000], [ 210,210], [195, 195], [160,160]], dtype=float)
velocity = np.array([[ 5,5], [8,2], [5,3], [10,-4]], dtype=float)
mass = np.array([ 10, 20, 5, 30 ], dtype=float)
size = np.array([ 15, 25, 15, 30 ], dtype=float)
def moveParticles(pos, lastpos, velocity, dt):
lastpos[:] = pos[:]
pos[:] += velocity * dt
这将使
pos
和
lastpos
。为了移动粒子,您必须调用以下函数:
moveParticles(pos, lastpos, velocity, 1)
其中我设置dt=1。我还假设,您希望有浮点坐标,如果没有,则应该生成整数数组。