There are several formulas out there for figuring out the reflected angle of a projectile that collides with a stationary wall at any angle using vectors and dot products, I'm trying to solve it using only angles and x and y components. My formulas must be incorrect though, as it's not working out correctly in my program.
$x$ and $y$ plot the trajectory of the projectile
$x_0$, $y_0$ is initial launch position
$s_0$ is initial launch speed
$a_0$ is initial launch angle (expressed in radians)
$t_0$ is initial launch time
$t$ is current timestep
$g$ is gravity
$$x = x_0 + s_0 (t - t_0) \cos(a_0) \tag1$$ $$y = y_0 + s_0 (t - t_0) \sin(a_0) - \frac12 g (t - t_0)^2 \tag2$$
The above two equations work, however the following four equations which I'm using to try to solve for the general case of collisions (using the law of reflection) with a stationary wall at any angle are not working for some reason.
$s_1$ is speed of projectile when it collides with the wall
$a_1$ is angle of projectile when it collides with the wall (expressed in radians)
$$s_1 = \sqrt{(s_0 \cos(a_0))^2} + \left(s_0 \sin(a_0) - g (t_1 - t_0)\right)^2 \tag3$$ $$a_1 = \arctan{\left(\dfrac{s_0 \sin(a_0) - g (t_1 - t_0)}{s_0 cos(a_0)}\right)} \tag4$$
$x_1$, $y_1$ is where the projectile collides with the wall
$t_1$ is the timestep when the projectile collides with the wall
$W$ is the angle of the wall relative to the $x$-axis (expressed in radians)
$$x = x_1 + s_1 (t - t_1) \cos(2W - a_1) \tag5$$ $$y = y_1 + s_1 (t - t_1) \sin(2W - a_1) - \frac12 g (t - t_1)^2 \tag6$$
This collision should not suffer any loss of speed, just simply change 2D direction based on the angle of the wall and the angle the projectile strikes it at.
While equations $(1)$ and $(2)$ work perfectly for plotting a trajectory without collisions, equations $(3)$, $(4)$, $(5)$, and $(6)$ give wildly inaccurate results when plotting the trajectory and trying to take into account wall bounces.