# How to calculate optimal distance for camera?

(Apologies for the cross post - no luck in beginners…).

Hi,

How can I calculate the optimal distance from a object for the camera eye-point such that all of the object is visible on screen (assume that the camera is axis aligned and that I only care about the x width of the object to look at).

As a follow up, given a cylinder of radius R, how can I calculate the optimal camera distance such that the end section (circular) of the cylinder is completely visible on screen?

Thanks for any help you may be able to give.

no luck in beginners

Come on, 30 minutes without an answer and you come to the conclusion that noone can answer your question?

Sorry - just impatient I guess Well, since you are so darn impatient, I wont even waste you time with an explanation of the theory behind this (since it would take another 30 minutes).

for your camera, you should already know the field of view in both the x and y directions.
lest say
fovX = 1/2 of the x field of view angle
fovY = 1/2 of the y field of view angle
r = radius of circle you wish to fit within the display

distX = r/tan(fovX)
distY = r/tan(fovY)

best fit camera distance = max(distX, distY)

Thanks. Explaination-wise, I am sure it involves some simple trigonometry Originally posted by LordKronos:
[b]Well, since you are so darn impatient, I wont even waste you time with an explanation of the theory behind this (since it would take another 30 minutes).

for your camera, you should already know the field of view in both the x and y directions.
lest say
fovX = 1/2 of the x field of view angle
fovY = 1/2 of the y field of view angle
r = radius of circle you wish to fit within the display

distX = r/tan(fovX)
distY = r/tan(fovY)

best fit camera distance = max(distX, distY)[/b]

Erm - ok, but what is fovY and fovX? I have a single FOV (around 60 deg) - is this the ratio of the FOV to the width and height of the window?

Originally posted by Robbo:
Erm - ok, but what is fovY and fovX? I have a single FOV (around 60 deg) - is this the ratio of the FOV to the width and height of the window?

tan(fovX) = apectRatio * tan(fovY)

If you need to find the actual fovX, you can apply the inverse tangent to both side, but it isnt necessary for these calculations.

P.S. Forgot to mention, if you are calling gluPerspective (most likely you do) then fovY is the first param, and aspectRatio is the second param.

[This message has been edited by LordKronos (edited 05-14-2002).]