How was this equation for the hypotenuse of a triangle derived? 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$
 A: 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

in $\triangle$AEC
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})$
A: If you substitute $x=z'\sin\theta$ and $z=z'\cos\theta$ into the formula you will get $z'=z'\sin^2\theta+z'\cos^2\theta$ which is a correct formula.
A: Let the point at which the horizontal dashed line at the top meets the vertical ($x$, in this case) axis be represented by $P$. Now drop a perpendicular to the slanted line ("the hypotenuse") from $P$. Let the intersection of that perpendicular with that line be called $Q$. Let the "red bullseye" (top-right corner) be $R$ and the origin (bottom-left "black bullseye") be $O$.
Now since $PR$ is parallel to the $z$-axis, it should be obvious that $\angle PRO = \theta_i$. 
Consider right $\triangle PQR$. Its hypotenuse is $PR$. Which means that $QR = PR\cos \angle PRQ = z\cos \theta_i$.
Now consider right $\triangle PQO$. Its hypotenuse is $PO$. $\angle POQ = 90^{\circ} - \theta_i$. Also, $OQ = PO \cos \angle POQ = x \cos (90^{\circ} - \theta_i) = x\sin \theta_i$.
Finally, since $OR = OQ + QR$, the length you want is $x\sin \theta_i + z\cos \theta_i$
