Results 1 to 3 of 3

Thread: spheres/plane intersection

  1. #1
    Member Contributor
    Join Date
    Jan 2002
    Posts
    96

    spheres/plane intersection

    I have been trying to write some functions to handle sphere/polyogon collision and am nearly finished but now I'm stuck again.

    The classifySphere(...) function shown below should tell me whether the sphere is infront of the plane, behind the plane, or intersects the plane. This is where the problem lies however because it only intersects the plane if the centre of the sphere is exactly on the plane.

    I have tested values for the ditance variable and they are in the region of 10000x too high/low. Why is that? I'm sure its a simple thing but I can't find it....
    Anyway here is the code :

    Code :
    SPHERE_POSITION classifySphere( Vector3d& centre, Vector3d& planeNormal, Vector3d& pointOnPlane, float radius, float &distance )
    {
    	//distance of polygon plane from origin
    	float distFromOrigin = float( planeDistance( planeNormal, pointOnPlane ) );
     
    	//distance of sphere centre to polgon plane
    	distance = dotProduct( planeNormal, centre ) + distFromOrigin;
     
    //	cout << "distance : " << distance << endl;
    //	cout << "radius : " << radius << endl;
     
    	if( absolute( distance ) < radius )
    	{
    		return INTERSECTS;
    	}
    	else if( distance >= radius )
    	{
    		return IN_FRONT;
    	}
     
    	return BEHIND;
    }
    Edit : Why does my code always get posted at varying font sizes?

    [This message has been edited by endo (edited 05-01-2002).]

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Holland
    Posts
    179

    Re: spheres/plane intersection

    endo,

    I think you should take out the '+ distFromOrigin' in the calculation of distance.
    Provided the planeNormal has length 1, the dot product with the sphere centre should produce the
    signed distance to the plane.

    As to the variable font: in Netscape the [ code ] sections are not shown in a fixed font

    HTH

    Jean-Marc

  3. #3
    Member Contributor
    Join Date
    Jan 2002
    Posts
    96

    Re: spheres/plane intersection

    Thanks JML, actually the cause was that planeNormal wasn't a unit vector, fixed that and all is good now. I am very happy now, that was some hard maths!!

    ps, I'm using IE5.xxx, guess I'll have to putup with the strange fonts

Similar Threads

  1. Intersection of Ray and y-plane
    By deerangle2 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-16-2017, 12:56 AM
  2. Intersection between a Line and a Plane
    By jenny_wui in forum OpenGL: General
    Replies: 3
    Last Post: 10-16-2010, 04:23 AM
  3. 3 spheres on a checkered plane causing me pain
    By MMMovania in forum OpenGL: Basic Coding
    Replies: 16
    Last Post: 04-28-2005, 05:19 AM
  4. Plane + Frustum Intersection
    By Gdo in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 06-30-2002, 09:01 AM
  5. Intersection with cutting plane
    By KurtCob in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 05-01-2001, 05:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean