Calculating new velocities of $n$-dimensional particles after collision I am working on a particle simulation where there is no gravitational force exerted on particles, they simply travel through space and, upon collision, change trajectories accordingly. There isn't a set number of dimensions the simulation can be run on, with the minimum being 2.
Each particle has three attributes: radius (each particle is an  $n$-ball of  $n$ dimensions corresponding to the simulation's dimensions), coordinates (a tuple describing its position), and velocity (another tuple describing how quickly it moves in any given direction, determining where it will be on the next iteration).
With the coordinates one can determine exactly the angle at which it strikes another particle, and that should be enough to determine the new velocities of both particles, or so I think. However, I'm not sure how to do this for an unknown amount of dimensions. I would presume a sigma function could describe this behaviour well, but I'm not sure how to write it. How might I go about doing so?
Any necessary information can be added upon request.
 A: The exchange in momentum (impulse $J$) happens along a single direction. With the simple model of just spheres you can calculate the direction from the positions of the particles
$$ \boldsymbol{n} = \frac{ \boldsymbol{r}_j - \boldsymbol{r}_i }{ \| \boldsymbol{r}_j - \boldsymbol{r}_i \| } $$
where $\| \boldsymbol{r}_j-\boldsymbol{r}_i \| = \sqrt{ (\boldsymbol{r}_j-\boldsymbol{r}_i) \cdot (\boldsymbol{r}_j-\boldsymbol{r}_i) } $. This depends on the dot product $\cdot$ which is defined for any dimension vectors.
So the change in velocity is $$ \begin{aligned} \Delta \boldsymbol{v}_i &= - \tfrac{J}{m_i} \boldsymbol{n} & \Delta \boldsymbol{v}_j &= + \tfrac{J}{m_j} \boldsymbol{n} \end{aligned} $$
and the value of $J$ is determined by the type of collision
$$ \begin{array}{c|c} 
\text{elastic} & \text{plastic}\\
\hline 
 J = 2 \frac{\boldsymbol{n} \cdot ( \boldsymbol{v}_i - \boldsymbol{v}_j )}{ \tfrac{1}{m_i} + \tfrac{1}{m_j}} &  J = \frac{\boldsymbol{n} \cdot ( \boldsymbol{v}_i - \boldsymbol{v}_j )}{ \tfrac{1}{m_i} + \tfrac{1}{m_j}}
 \end{array}$$

Note that symbols in boldface are vectors and normal letters are scalar values.
