I've been staring at this for quite a while and simply can't understand how they got the equation for the hypotenuse. Probably has something to do with it being 5am my time!

I'm confused because (where z' is the hypotenuse):
$cos\theta_i = \frac{z}{z'}$
$sin\theta_i = \frac{x}{z'}$
Therefore:
$z'*cos\theta_i = z$
$z'*sin\theta_i = x$
So how do you go from those to the following?
$z' = x*sin\theta_i + z*cos\theta_i$
It is really simple,
Draw a $\perp$ from Z to the hypotenous you will get two triangles then simply break the component of x and z on hypotenous and add them.
Component of z along z' is z $\cos(\theta_{1})$ and component of x along z' is z $\cos(90-\theta_{1})$=x $\sin(\theta_{1})$
so, z'= z $\cos(\theta_{1})$+x $\sin(\theta_{1})$
e.g.
Let $\theta_{1}$=60
cos(B)=$\frac{AE}{x}$=$\cos(90-60)$= sin(60)
AE=xsin(60)
similarly, in $\triangle$BEC, $\frac{BE}{z}$=cos(60)$\Rightarrow$ BE=zcos(60)
therefore z'= BE+AE= xsin(60)+zcos(60)
since we assumed $\theta_{1}$=60
z'= z $\cos(\theta_{1})$+x $\sin(\theta_{1})$