Copying this from another thread where i posted this as the answer but as Wyck suggested, the correct answer is the first one.
There is the whole derivation of it but I'll be discussing a brief overview.
This is for the perspective projection where the line joining the eye and the center of the projection/image plane is perpendicular to it. Like here
As we can easily see, by similar triangles $\triangle ABC$ and $\triangle AEF$ we have
$Y_p / Y = D/-Z$
where $Y_p$ is the projected $Y$ coordinate on to the image plane. $AB = D$ is the total distance from eye to the image plane and is usually set to 1.
Hence we have,
$Y_p = (Y*D)/-Z$
We can easily ee from here that,
$tan(\theta_{fov}/2) = 1/AB$
$tan(\theta_{fov}/2) = 1/D$
$D = 1 /tan(\theta_{fov}/2)$
Hence we have,
$Y_p = \frac{Y}{-Z*tan(\theta_{fov}/2)}$
For more details check the complete answer here