how far translate to deep

Hi, my question is simple but I can’t find answer anywere.

I draw rectangle with rWidth that (0, 0) is in the center. How far translate it to deep along Z axis so as to left and right border of rect touch exactly screen border with sWidth?

I find this: sWidth/sin(45) but this isn’t precise (bit deeply). Is there any formula on this?

Im using OpenGL ES on win mobile.

Tangent is opposite over adjacent.
Thus, adjacent is opposite over tangent.

So, the distance (adjacent) is rectwidth/2 (opposite) over tan(fov/2). Following your naming:

d = (rWidth/2) / tan(fov/2)

Where fov is the field of view of your camera.

Yeah, Im stu…

It works for me with height, because my gluPerspective function was calculated on fov in horizontal along y axis.
Im actualy changing to fovx, thanks a lot.

Then do

d = (rWidth/2) / (tan(fov/2)*aspect)