I am trying to figure out where to position the camera to view a certain rectangle (of a planar slice) in my scene. I need to do this on the fly so I can’t just find a position that works, I need to be able to calculate it. When this didn’t seem to work I went back to a very basic test scene and it appears that I do not fully understand how it works. Here is a simple setup:

I have a 100*100*100 cube positioned at (50, 0, 0). This should mean that one of the faces have the four corners (0, -50, -50), (0, 50, -50), (0, 50, 50) and (0, -50, 50), ie a 100*100 square on the X=0 plane. Next I place a camera at (-x, 0, 0) looking in the direction of positive x, towards this face. The question is how far away, ie what must x be, to show the entire height of the face (but no more), like shown in this picture.

The vertical field of view for the camera is set to 90 degrees, so the angle up the the camera midline to the upper frustrum should be 45 degrees, and this should view half of the height of the cube face, which is 50, like in this delightful piece of coder art.

So basic trigonometry should indicate tan(45 deg) = 50 / x, which yields x = 50. However setting the camera x position to -50 does not show the full height of the cube, hand adjusting it seems to end up showing the full height at around -88. Am I completely misunderstanding the camera system?