Oh you meant the corners of the bounding box! No idea why I could not get this earlier.

So, I have my function for testing if a halfspace intersects a bounding box like this:

Code:

**
* Increase counters if needed.
* @param q - compare it with epsilon
* @param in_at - counter for points inside,
* or at the plane of the halfspace
* @param out - counter for points outside
* the halfspace
*/
void Guadtree::incCounters(const double& q, size_t& in_at, size_t& out)
{
/*
* q < 0: (x, y, z) is inside the halfspace.
* q = 0: (x, y, z) is at the plane of the halfspace.
* q > 0: (x, y, z) is outside the halfspace.
* Use epsilon, because of double variables.
*/
if(q < -epsilon || (-epsilon <= q && q <= epsilon))
in_at++;
else
out++;
}
/**
* Test if a halfspace intersects a bounding box.
* @param halfspace - the halfspace to be tested
* @param minBox - the min of the bounding box
* @param maxBox - the max of the bounding box
* @return - answer of test
*/
bool Guadtree::halfspaceIntersectsBox(const Halfspace& halfspace, const Point3d*& minBox, const Point3d*& maxBox)
{
size_t in_at = 0; // Counter for corners inside, or at the plane, of the halfspace
size_t out = 0; // Counter for corners outside of the halfspace
const Point3d halfspaceCoords = halfspace.getCoords();
const double halfspaceD = halfspace.getD();
/* Check all the corners of the bounding box, eight in number.
* The corners are:
* min.x min.y min.z
* max.x min.y min.z
* min.x max.y min.z
* max.x max.y min.z
* min.x min.y max.z
* max.x min.y max.z
* min.x max.y max.z
* max.x max.y max.z
*/
double q = halfspaceCoords * *minBox - halfspaceD;
incCounters(q, in_at, out);
q = halfspaceCoords.x() * maxBox->x() + halfspaceCoords.y() * minBox->y()
+ halfspaceCoords.z() * minBox->z() - halfspaceD;
incCounters(q, in_at, out);
/* If at least one corner is inside(or at the plane), and one corner outside,
* then the plane of the halfspace intersects the bounding box.
*/
if(in_at >= 1 && out == 1)
return true;
q = halfspaceCoords.x() * minBox->x() + halfspaceCoords.y() * maxBox->y()
+ halfspaceCoords.z() * minBox->z() - halfspaceD;
incCounters(q, in_at, out);
if(in_at >= 1 && out == 1)
return true;
q = halfspaceCoords.x() * maxBox->x() + halfspaceCoords.y() * maxBox->y()
+ halfspaceCoords.z() * minBox->z() - halfspaceD;
incCounters(q, in_at, out);
if(in_at >= 1 && out == 1)
return true;
q = halfspaceCoords.x() * minBox->x() + halfspaceCoords.y() * minBox->y()
+ halfspaceCoords.z() * maxBox->z() - halfspaceD;
incCounters(q, in_at, out);
if(in_at >= 1 && out == 1)
return true;
q = halfspaceCoords.x() * maxBox->x() + halfspaceCoords.y() * minBox->y()
+ halfspaceCoords.z() * maxBox->z() - halfspaceD;
incCounters(q, in_at, out);
if(in_at >= 1 && out == 1)
return true;
q = halfspaceCoords.x() * minBox->x() + halfspaceCoords.y() * maxBox->y()
+ halfspaceCoords.z() * maxBox->z() - halfspaceD;
incCounters(q, in_at, out);
if(in_at >= 1 && out == 1)
return true;
q = halfspaceCoords * *maxBox - halfspaceD;
incCounters(q, in_at, out);
if(in_at >= 1 && out == 1)
return true;
}

Is it correct?

What is your opinion about this code? It is C++.

>Well, you did learn a very valuable lesson, though: always make sure you understand how your task will be evaluated, and direct your efforts accordingly.

>It's a good rule to go by even if you do the evaluation yourself.

We learn and get better constantly!

//At 7.30 I am leaving for vacation, for a week and I decided not to take a computer/laptop with me. I have to work at my aunt's restaurant too.