I have a 3D AABB defined by two sets of points a min/max.
I'd like to define the 6 planes that make up the sides of the AABB, such that any point that is within the AABB will have a positive signed-distance.
My plane definition is comprised of a normal (x,y,z) and a constant D, Corresponding to the Ax + By +Cz + D = 0 form plane equation.
struct myplane {
double nx,ny,nz;
double D;
};
Note: nx,ny, and nz are normalized.
The AABB struct is as follows:
struct myAABB {
point3d min;
point3d max;
};
I'm currently defining instances of the AABB sides like so:
myplane p0 = myplane{-1.0f, 0.0f, 0.0f,aabb.max.x);
myplane p1 = myplane{ 0.0f,-1.0f, 0.0f,aabb.max.y);
myplane p2 = myplane{ 0.0f, 0.0f,-1.0f,aabb.max.z);
myplane p3 = myplane{+1.0f, 0.0f, 0.0f,aabb.min.x);
myplane p4 = myplane{ 0.0f,+1.0f, 0.0f,aabb.min.y);
myplane p5 = myplane{ 0.0f, 0.0f,+1.0f,aabb.min.z);
where aabb is in this case is: min(-1,-1,-1) max(1,1,1)
The problem is that points in the AABB return a positive distance for the planes p0,p1 and p2, however not so for planes p3,p4 and p5, as they return negative distances which seem to indicate the points are on the other side.
For example the origin point **(0,0,0)** should return a positive distance of 1 for each of the planes however does not for planes p3,p4 and p5.
The signed-distance calculation being used is:
double distance(myplane& p, const point3d& v)
{
// p.normal dot v + D
return (p.nx * v.x) + (p.ny * v.y) + (p.nz * v.z) + p.D;
}
I think my equations are wrong in some way, but I can't seem to figure it out.