Camera placement sphere for an always fully visible object

Given an object:

• With the bounds [x, y, z, width, height, depth]
• And an orthographic projection [left, right, bottom, top, near, far]

I want to determine the radius of a sphere which allows me to randomly place my camera on so that:

1. The object is fully visible from all positions on this sphere
2. The sphere radius is the smallest possible value while still satisfying 1.

Assume the object is centered around the origin.
How can I find this radius?

I'm currently using sqrt(width^2 + height^2 + depth^2) but I'm not sure that's the correct value, as it doesn't take the camera into account.

I'm sorry for confusing a few things here. My comments below should clarify what I'm trying to do actually.

• have you tried searching in math.stackexchange.com I think this question would be better suited there. May 21 '12 at 14:38
• Are you sure you mean an orthographic projection? Not a perspective one? Given the properties of orthographic projections, you'll get the same object proportions with whatever sphere radius you set, so there's no answer to this question as-is. May 21 '12 at 19:13
• @lorancou: that is not true since the camera location will affect the viewing angle May 21 '12 at 22:47
• @SamHocevar True, but the correct answer for an orthographic essentially doesn't take the camera into account - all points along the camera's view axis are equivalent since an orthographic projection has no 'FOV' associated with it; for instance, if your camera is looking parallel to the Z axis, then it makes no difference if it's at (0, 0, -10) or (0, 0, -10000). The 'placement sphere' doesn't make sense for an orthographic projection. May 21 '12 at 23:27
• Indeed the viewing angle still matters, but as Steven said, changing the sphere radius / viewing distance is pointless. May 22 '12 at 13:09

• I'm using an orthographic camera and I confused a few things in my initial question. Sorry about that, but thanks for that answer as it will come in handy later on :) May 22 '12 at 21:14

You specify the projection transformation but not the view transformation. I will assume that the camera simply looks in the z direction. I will also assume that you want the sphere radius to be the largest possible, not the smallest (otherwise, just choose radius = 0).

Note that since you have an orthographic projection, the z coordinates do not really matter apart from ensuring that the object fits inside the near and far planes. Your scene will look exactly the same whatever the z coordinates of your objects are. So your problem becomes a matter of fitting your object's rectangle boundaries inside the camera's viewport rectangle.

Because the problem is symmetric, it is obvious that if such a sphere exists, its x and y coordinates are precisely your object's x and y coordinates. Then, the radius is:

radius = min((right - left - width) / 2,
(top - bottom - height) / 2,
(far - near - depth) / 2);

Note that the third term (far - near - depth) is probably superfluous. You really only care about the x and y directions.

And the camera coordinates:

cx = x
cy = y
cz = z - depth/2 - near - radius;

Again, the z value is probably not that important and you could just move your camera on a disc rather than a sphere.

• I'm not sure I understood correctly, or maybe I just wasn't clear what I mean. I need the radius of the sphere which makes sure that regardless of the point I pick on the sphere, I can see the object without clipping. This is for gluLookAt(sphere_x, sphere_y, sphere_z, 0, 0, 0, 0, 1, 0). May 21 '12 at 18:14
• @BengtR: okay, then my assumption that the view vector is (0,0,1) no longer stands and you can indeed ignore most of what I wrote. I'll try to rework on an answer. May 21 '12 at 18:48