Original Post
I'm trying to find minimum bounding sphere for a frustum and haven't succeeded so far.
the method I use is very simple, assuming frustum is symmetric , the center of the sphere should be on the line between two centers of frustum planes (shown in the image)
so we have :
1) Dot(P - A, P - A) = Dot(P - B, P - B)
2) P = S + t*N

by putting P into the equation (1), I could solve t and find sphere center
but I can't get corrent results and two distances are never the same after solving it
can someone tell we where I'm doing wrong ? or how can I compute the minimum sphere of the frustum ?
here is the code :
the method I use is very simple, assuming frustum is symmetric , the center of the sphere should be on the line between two centers of frustum planes (shown in the image)
so we have :
1) Dot(P - A, P - A) = Dot(P - B, P - B)
2) P = S + t*N

by putting P into the equation (1), I could solve t and find sphere center
but I can't get corrent results and two distances are never the same after solving it
can someone tell we where I'm doing wrong ? or how can I compute the minimum sphere of the frustum ?
here is the code :
// 0~3 points of 'frustPts' = nearPlane
// 4~7 points of 'frustPts' = farPlane
void CSM::CalcMinSphere( const math::Vector3f frustPts[8], math::Sphere* sphere )
{
math::Vector3f S = (frustPts[0] + frustPts[2]) * 0.5f; // center pt - near plane
math::Vector3f S2 = (frustPts[4] + frustPts[6]) * 0.5f; // far pt - near plane
math::Vector3f N = S2 - S;
math::Vec3Normalize(N, &N);
math::Vector3f A = frustPts[0];
math::Vector3f B = frustPts[4];
fl32 d = 2.0f*(math::Vec3Dot(N, A) - math::Vec3Dot(N, B));
fl32 t = ( math::Vec3Dot(A, A) - math::Vec3Dot(B, B) - 2.0f*S.x*(A.x+B.x) - 2.0f*S.y*(A.y+B.y) - 2.0f*S.z*(A.z+B.z) ) / d;
math::Vector3f center = S + N*t;
fl32 radius = math::Vec3Length( B - center );
fl32 d1 = Vec3Dot( center - A, center - A );
fl32 d2 = Vec3Dot( center - B, center - B );
_ASSERT( Fl32Equal(d1, d2) ); // asset failure !!! ( + we have invalid bounding sphere)
sphere->Set(center.x, center.y, center.z, radius);
}