Dec 07 2015 | 1:51 am

I want to implement a 'bounce' like behavior for a number of objects moving in space and bouncing off walls. I can do this in javascript, or using a million patches iterating each cell, but I'm wondering if it's possible to do without iterating the cells, and just use smart jit operator and expressions.

i have one dimensional (1 cell per object), 3 plane (xyz) matrices
- pos
- vel
- dir // think of this as a 'bounce' property for each plane (component). either +1 or -1. This is what I flip when an object hits a wall. (I don't want to flip the sign of the vel matrix on bounce, because it's being written into by external processes. So I want to store the 'flippedness' in a separate matrix).

`pos = vel * dir + pos`

this is easy with jit.+ and jit.*

but I also want to bounce (i.e. flip the sign of dir) of any individual cell plane, when the current cell plane value goes beyond a threshold. And the threshold is dependent on the plane.
i.e. my world boundary is [xmin ymin zmin] -> [xmax ymax zmax]

`for each cell i: if(pos[i].x < xmin) { pos[i].x = xmin; dir[i].x *= -1; } else if(pos[i].x > xmax) { pos[i].x = xmax; dir[i].x *= -1; } if(pos[i].y < ymin) { pos[i].y = ymin; dir[i].y *= -1; } else if(pos[i].y > ymax) { pos[i].y = ymax; dir[i].y *= -1; } if(pos[i].z < zmin) { pos[i].z = zmin; dir[i].z *= -1; } else if(pos[i].z > zmax) { pos[i].z = zmax; dir[i].z *= -1; }`

Is it possible to do the above on a matrix level (i.e. not cell level)? e.g. in numpy (python matrix lib) there'd be syntax something like

`dir[pos < worldmin] *= -1 pos[pos`

------
update: here's a toy example