near, far clipping

I have a dataset which contains nodes, edges, faces & volumes. I calculate the maximum & minimum x,y,z values of the data & get the radius of the bounding sphere.
I use the radius & the camera distance from 0,0,0 to calculate the near & far clipping values like this:

double cameraDist = distance from camera to origin(0,0,0)

farClip = ( cameraDist + radius );
if ( cameraDist > radius )
nearClip = ( ( cameraDist - radius ) );
else
nearClip = ( ( cameraDist / radius ) );

::glMatrixMode( GL_PROJECTION );
::glLoadIdentity();

gluPerspective( fieldOfView, aspectRatio, nearClip, farClip );

::glMatrixMode( GL_MODELVIEW );
::glLoadIdentity();

For the most part, this works fine as I zoom in & out. However, for a couple of datasets, the first few times the nearclip is calculated in the else statement, some far polygons are being clipped. As I keep zooming in, they come back & it looks ok.
If I calculate the nearclip as
nearClip = farClip / 1.0e3;
this problem goes away, but I can’t zoom in as close.

Any ideas on how else to calculate the near clipping plane?

nearclip should be farclip-2*radius, in all cases. You may have to offset both values a bit to account for insufficient numerical precision.

Zooming is better accomplished by narrowing the field of view angle, don’t touch camera distance for this. As you’ve seen, this will easily get you in trouble.