I have to determine the distance along the Z-axis from O to where the upper line crosses the Z-axis and makes angle between the Z-axis and the line.

The lower line which length equals L starts at the origin and makes an angle between the Z-axis and the line itself (so the angle between the line and the X-axis is )

This distance along the Z-axis equals (Lcos + Lsin cotan )ez

ez is the unit vector and there should be an arrow above the letter e.

I don't understand why you can express this distance like this.

Because I'm not certain if the rest of you can see this picture, since it's posted on a secured website (login), I have posted the same picture as an attachment.