photons can hit electrons as if they were particles, and we can apply conservation of energy and momentum.

incident photon---> electron at rest* ---> *splits* electron moves with momentump', photon moves with momentumq', with angle theta between them.

electron at rest has energy E=mc^2 and no momentum.

The mathematics I've been shown makes sense, all up to one point:

using the conservation of momentum,

q=q' +p'

then they square the above term and suddenly:

p^2 = (q' -q)^2 = q'^2 + q^2 -2q' (dot product)q

Can anyone here explain how they did that?