I want to numerically simulate the motion of a particle (unit mass) in $N$-dimensional space according to the force $f(\vec{x})$ and bounded by a set of linear constraints (equalities as well as inequalities):
$$A_i \vec{x} = \vec{c_i}$$
$$B_j \vec{x} \leq \vec{d_j}$$
The behavior of the particle when it comes in contact with a "wall" formed by an inequality is a perfectly inelastic collision.
What I'm thinking right now is something like this:
for step in range(total_time//dt):
p += f(x) * dt
x += p * dt
if violate_constraints(x):
x, p = correct(x, p)
It is easy to check if $\vec{x}$ violates any constraints, but I'm not sure how to implement the correct(x, p)
part.
I think the correct behavior for correct(x, p)
is to put the position $\vec{x}$ back to the closest point in the "allowed" space, and project $\vec{p}$ onto the intersection of subspaces according to which constraints $\vec{x}$, before correction, broke. However,
- I have no proof if this is correct
- I don't know how to put $\vec{x}$ back to the closet point in the allowed space
EDIT: Putting $\vec{x}$ back to the closet point in the allowed space is what I think should correctly handle the "corner" cases where the particle comes in contact with 2 or more walls.