# troubles with plane - cube intersection

This topic is 4793 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello. Im trying to do frustum culling, but i cant get it to work properly. Iv concluded that it must be the intersection test between the 3d plane and the quadtree node's bounding cube (a 2d rect). I am using a intersection algorithm i got from the book "3d Terrain Engine programming with dx9". And im getting some really strange results. For instance, when i create a plane at the point 0,0,0 with the normal 0,0,1. Only the first row of nodes in the quadtree after the position 0,0 reports as beeing behind the plane, and all other nodes behind them dont. This is wrong since all nodes below 0,0 of the tree should be behind a plane at those coordinages. Anyway this is what the algorithm looks like, if anyone can catch what is wrong with it i would be very happy.
//-----------------------------------------------------------------------------
// Name: classify_plane
// Desc:
//-----------------------------------------------------------------------------
inline int classify_plane(const cube_t& cube, const plane_t& plane)
{
vector3d_t min_point, max_point;

// build two points based on the direction
// of the plane vector. min_point
// and max_point are the two points
// on the rectangle furthest away from
// each other along the plane normal

if (plane.m_normal.x > 0.0f)
{
min_point.x = (float)cube.m_point0.x;
max_point.x = (float)cube.m_point1.x;
}
else
{
min_point.x = (float)cube.m_point1.x;
max_point.x = (float)cube.m_point0.x;
}

if (plane.m_normal.y > 0.0f)
{
min_point.y = (float)cube.m_point0.y;
max_point.y = (float)cube.m_point1.y;
}
else
{
min_point.y = (float)cube.m_point1.y;
max_point.y = (float)cube.m_point0.y;
}

if (plane.m_normal.z > 0.0f)
{
min_point.z = (float)cube.m_point0.z;
max_point.z = (float)cube.m_point1.z;
}
else
{
min_point.z = (float)cube.m_point1.z;
max_point.z = (float)cube.m_point0.z;
}

// compute the signed distance from
// the plane to both points
float dmin = plane.signed_distance(min_point);
float dmax = plane.signed_distance(max_point);

// the rectangle intersects the plane if
// one value is positive and the other is negative
if (dmin * dmax < 0.0f)
{
return PLANE_INTERSECT;
}
else if (dmin)
{
return PLANE_FRONT;
}

return PLANE_BACK;
}



##### Share on other sites
the way id intersect an AABB with a plane:

you have 6 values defining the AABB. given these you can contruct the 8 corner points of the AABB. if all 8 points lie on the same side of the plane (easy to check), it doesnt intersect.

##### Share on other sites
Hm plane interception.
The way as I see it, you should do the following:

1. Take each of box 8 vertices and see which one are connected
2. For each connected pair of vertices check them via the plane
3. if A lies on other SIDE than B then it intercepts

How to determine on which side it lies? That does not matter.
If distance point to plane A is positive and distance point to plane B is negative or vice versa, it intercepts. That's all there is.
If both points are +away or -away from the plane they do not intercept.

##### Share on other sites
Hi peter_b,

The algorithm you posted is standard and is faster than the test-each-corner method.

One line that I noticed was the 'else if (dmin)' line. It seems like this should be dmin >= 0 (or perhaps <= 0, depending on your plane convention). Unless I'm missing something, the current version will test true for any non-zero value, which means an AABB that is behind the plane will register as in front. Perhaps that is causing your problem.

##### Share on other sites
thanks alot jyk! that was it! :-D

##### Share on other sites
Quote:
 thanks alot jyk! that was it! :-D

:-)