Sphere-Plane collision test I'm worried about my own attempt at a solution for a Sphere-Plane collision testing. I originally implemented a solution I found on a mix of Game Development websites around the place, which was similar enough to the following:

bool intersecting(BoundingSphere const&amp; s, Vector3 const&amp; s_origin, BoundingPlane const&amp; p, float const p_distance) {
    Vector3 const p_origin = p.normal * p_distance;
    Vector3 const cp = s_origin + p.normal * dot((p_origin - s_origin), p.normal);

    return (distance2(s_origin, cp) &lt; s.radius * s.radius);
}


But I have recently spent a bit more time doing linear algebra since and basic geometry, and decided upon revising the above solution (to see if I understood the problem space better).

In thinking about it as a simple check: distance of a point from a line being less than the radius. I came up with the following:

bool intersecting2(BoundingSphere const&amp; s, Vector3 const&amp; s_origin, BoundingPlane const&amp; p, float const p_distance) {
    return abs&lt;float&gt;(dot(p.normal, s_origin) - p_distance) &lt; s.radius;
}


It has so far passed all my tests practically, but I still worry about my mathematical ability and I don't want an edge case to bite me in the ass that I might have missed. One thing I have definitely noticed is the solution is highly sensitive to the normalised form of the plane normal. If it is simply a rough estimation, ie not truly normalised, it will fail completely (exponential error).

The fact I never saw a solution that short worries me haha.

edit: My testbed: http://pastie.org/3512889

proposed tags: collision-detection &amp;&amp; math
I'm not sure what kind of error your getting but here is a very simple collision test:

#include &lt;cmath&gt;
#include &lt;iostream&gt;

class float3 {
        public:
                float x,y,z;
};

class float4 {
        public:
                float a,b,c,d;
                float norm() const{
                        return sqrt(a*a+b*b+c*c);
                }
};

typedef float4 plane;

class sphere {
        public:
                float3 position;
                float radius;
};

float project( const float3 &amp; spherePos, const plane &amp; p){
        return std::abs( spherePos.x*p.a + spherePos.y*p.b + spherePos.z*p.c + p.d );
}

bool const collision( const sphere &amp; s, const plane &amp; p){
        return project(s.position,p)/p.norm() &lt; s.radius;
}

int main( int argc, char * argv[]){

        plane p = {0.0,-1.0,0.0, 2.0 };
        sphere s = { {0.0,1.5,0.0}, 1.0 };

        if ( collision(s,p) )
                std::cout &lt;&lt; "Collision detected" &lt;&lt; std::endl;

}


The advantage here is that you don't need a normalized plane. The line that bothers me is this:

return abs&lt;float&gt;(dot(p.normal, s_origin) - p_distance) &lt; s.radius;


Just write your solution such that it can handle un-normalized planes. If you're working with normalized planes (which may be what is contained in "p.normal"?) I believe you need :

return abs&lt;float&gt;(dot(p.normal, s_origin) + p_distance) &lt; s.radius;


See the wolfram page on this topic - it is straight forward. It is not clear how you have implemented BoundingPlane - but if you are getting errors, that would be the first place to look.