From the conservation laws, we have the three equations
m1v1i−m1v1fcosθm1v1fsinθm1v21i−m1v21f=m2v2fcosϕ,=m2v2fsinϕ,=m2v22f.(1)(2)(3)(1)m1v1i−m1v1fcosθ=m2v2fcosϕ,(2)m1v1fsinθ=m2v2fsinϕ,(3)m1v1i2−m1v1f2=m2v2f2.Summing the squares of (1) and (2) eliminates ϕϕ. The RHS of the resultant equation contains v22fv2f2 which can be eliminated using (3). Then, one would obtain a quadratic equation in terms of v1fv1iv1fv1i, which can be solved to obtain the desired equation
v1fv1i=m1m1+m2[cosθ±cos2θ−m21−m22m21−−−−−−−−−−−−−−√].v1fv1i=m1m1+m2[cosθ±cos2θ−m12−m22m12].For the next equation, we rotate the axes to obtain the angle θ+ϕθ+ϕ more easily. Here, the conservation laws are
m1v1icosϕ−m1v1fcos(θ+ϕ)m1v1isinϕm1v21i−m1v21f=m2v2f,=m1v1fsin(θ+ϕ),=m2v22f.(4)(5)(6)(4)m1v1icosϕ−m1v1fcos(θ+ϕ)=m2v2f,(5)m1v1isinϕ=m1v1fsin(θ+ϕ),(6)m1v1i2−m1v1f2=m2v2f2.