You have two balls of equal masses: Ball 1 and Ball 2.
You are given the initial vector velocities (i.e velocity represented as a vector, with x and y components) as well as the initial x and y positions of the two balls.
How would you find the final x and y velocities of the two balls?
Basically, for my program I need an angle-free representation, meaning the equation doesn't require the angles of the balls. Here are two equations that I found (sorry, i'm not allowed to post images!):
https://wikimedia.org/api/rest_v1/media/math/render/svg/14d5feb68844edae9e31c9cb4a2197ee922e409c
https://wikimedia.org/api/rest_v1/media/math/render/svg/f5b3b7479d07075c0c5ce3f30db29f25c8a0449c
The first equation does give you the final x-velocity and y-velocity, but it isn't angle-free. The second equation is angle-free, but doesn't give the x and y components of the velocity.
Is there any equation that could achieve this? (Being angle free and resulting in a vector)
I will explain why your first picture is exactly what you need for your program, it takes a very slight bit of algebra and definitions to write it out, for instance, given two vectors $\vec{a} = (a_1,a_2,a_3,\dots, a_n) $ and $\vec{b} = (b_1,b_2,b_3,\dots,b_n)$, then: $$\langle \vec{a}, \vec{b} \rangle \equiv \sum_i a_i b_i = a_1b_1 + a_2b_2 + \dots a_nb_n $$ When the field of scalars used is $\mathbb{R}$ this product is bilinear in its arguments, that is $$\langle a + c, b \rangle = \langle a, b \rangle + \langle c, b \rangle$$ and $$\langle a , b + c \rangle = \langle a, b \rangle + \langle a, c \rangle$$ hence $$\langle a + c, b+d \rangle = \langle a, b \rangle + \langle a, d \rangle + \langle c, b \rangle + \langle c, d \rangle$$ Additionally $$||\vec{a}|| \equiv \sqrt{\vec{a} \cdot \vec{a}} \rightarrow ||\vec{a}||^2 = \vec{a} \cdot \vec{a} = \langle \vec{a}, \vec{a} \rangle $$ The first picture contains such objects, lets start with the first one ($M=m_1 + m_2$): \begin{eqnarray*} \vec{v}_1' &=& \vec{v}_1 - \frac{2m_2}{M}\frac{\langle\vec{v}_1 - \vec{v}_2, \vec{x}_1 - \vec{x}_2 \rangle}{||\vec{x}_2 - \vec{x}_1 ||^2}(\vec{x}_2 - \vec{x}_1) = \vec{v}_1 - \frac{2m_2}{M}\frac{\langle\vec{v}_1 - \vec{v}_2, \vec{x}_1 - \vec{x}_2 \rangle}{\langle \vec{x}_2 - \vec{x}_1,\vec{x}_2 - \vec{x}_1 \rangle}(\vec{x}_2 - \vec{x}_1) \\ &=& \vec{v}_1 - \frac{2m_2}{M}\frac{(\vec{v}_1\cdot\vec{x}_1 - \vec{v}_1 \cdot \vec{x}_2 - \vec{v}_2 \cdot \vec{x}_1 + \vec{v}_2\cdot \vec{x}_2)}{(\vec{x}_2\cdot\vec{x}_2 - \vec{x}_2 \cdot \vec{x}_1 - \vec{x}_1 \cdot \vec{x}_2 + \vec{x}_1\cdot\vec{x}_1)}(\vec{x}_2 - \vec{x}_1) \\ &=& \vec{v}_1 - \frac{2m_2}{M}\frac{(v_{1x}x_{1x} + v_{1y}x_{1y} - v_{1x}x_{2x} - v_{1y}x_{2y} - v_{2x}x_{1x} - v_{2y}x_{1y} + v_{2x}x_{2x} + v_{2y}x_{y})}{(v_{1x}x_{1x} + v_{1y}x_{1y} - v_{1x}x_{2x} - v_{1y}x_{2y} - v_{2x}x_{1x} - v_{2y}x_{1y} + v_{2x}x_{2x} + v_{2y}x_{y})}(\vec{x}_2 - \vec{x}_1) \end{eqnarray*} Those large pieces are all in terms of the given initial components of the velocities and positions where I have used subscripts to denote the first and second vectors x and y components. This single equation is also two equations in one for the x and y components of $\vec{v}_1'$. $$v_{1x}' = v_{1x} - \frac{2m_2}{M}\frac{(v_{1x}x_{1x} + v_{1y}x_{1y} - v_{1x}x_{2x} - v_{1y}x_{2y} - v_{2x}x_{1x} - v_{2y}x_{1y} + v_{2x}x_{2x} + v_{2y}x_{y})}{(v_{1x}x_{1x} + v_{1y}x_{1y} - v_{1x}x_{2x} - v_{1y}x_{2y} - v_{2x}x_{1x} - v_{2y}x_{1y} + v_{2x}x_{2x} + v_{2y}x_{y})}(x_{2x} - x_{1x}) $$ And $$v_{1y}' = v_{1y} - \frac{2m_2}{M}\frac{(v_{1x}x_{1x} + v_{1y}x_{1y} - v_{1x}x_{2x} - v_{1y}x_{2y} - v_{2x}x_{1x} - v_{2y}x_{1y} + v_{2x}x_{2x} + v_{2y}x_{y})}{(v_{1x}x_{1x} + v_{1y}x_{1y} - v_{1x}x_{2x} - v_{1y}x_{2y} - v_{2x}x_{1x} - v_{2y}x_{1y} + v_{2x}x_{2x} + v_{2y}x_{y})}(x_{2y} - x_{1y}) $$ As can be seen this is entirely without any mention at all of the angle of impact, and is solely in terms of the initial components. A similar argument can be applied to the second equation to obtain the four equations for the components of the final velocity.