Reputation: 97
The object is in the center of the 3D plane. I know the object's bounds.
For the 3D plane, X is from left to right, Y is from bottom to top, and Z is from inside of the screen to the outside. The object is facing positive Z direction.
I want to place my camera in X=0, Y=0, and Z=somewhere so that the camera can see the whole object from its left-most to right-most, top-most to bottom-most, and its front side.
So guys, please help me here, Z= ...?
Upvotes: 4
Views: 737
Reputation: 79471
Let R be the radius of the bounding sphere for your object.
Let V be the vertical field of view angle, 0 < V < 90 degrees.
Let H be the horizontal field of view angle, 0 < H < 90 degrees.
Then the distance you need to place your camera from the object is Z = R / sin(min(V,H)).
Here is what the derivation is for the distance Z needed for a full vertical view of the object. Solve for Z to get Z = R / sin(V).
A similar derivation for the distance Z needed for a full horizontal view gives Z = R / sin(H). Since we want both a full vertical and horizontal view, we use Z = max(R / sin(V), R / sin(H)) = R / sin(min(V,H)).
Upvotes: 4