# Creating the 6 clipping planes of a cube correctly.

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

## Recommended Posts

Hello there, I have a plane class that defines a plane as follows:
        /// <summary>
/// If we have a Point available that we know lies on the Plane.
/// We can compute the distance directly from this Point and the plane normal using:
/// distance (d) = (Vector3.Dot(Point, Normal))
/// </summary>
/// <param name="normal">Plane Normal</param>
/// <param name="point">Point that lies on Plane</param>
public CD_Plane(Vector3 normal, Vector3 point)
{
Normal = Vector3.Normalize(normal);
D = Vector3.Dot(Normal, point);

.......


When creating the 6 clipping planes of a cube I am currently doing the following:
            position = centre;
normal = normal_Surface;

Vector3 tangent = Vector3.Cross(normal, Vector3.UnitZ);

if (tangent.LengthSquared() < 0.0001f)
{
tangent = Vector3.Cross(normal, Vector3.UnitY);
}

Vector3 binormal = Vector3.Cross(normal, tangent);

//=============================================
//------- [Calculate Boundary Planes] ---------
//=============================================
float d = Vector3.Dot(centre, tangent);

plane_Left = new CD_Plane(tangent, tangent * (width * 0.5f + d));
plane_Right = new CD_Plane(-tangent, -tangent * (width * 0.5f - d));

d = Vector3.Dot(centre, binormal);

plane_Bottom = new CD_Plane(-binormal, -binormal * (height * 0.5f - d));
plane_Top = new CD_Plane(binormal, binormal * (height * 0.5f + d));

d = Vector3.Dot(centre, normal);

plane_Back = new CD_Plane(-normal, -normal * (depth * 0.5f - d));
plane_Front = new CD_Plane(normal, normal * (depth * 0.5f + d));


The problem is that if the projection onto the axis for the plane is 0, then the plane is not in the right location based on the centre. For example if the centre of the cube is (5, 0, 0) and the tangent is (1, 0, 0) then d would be 5. Therefore a plane created using n = tangent and the distance along n [tangent * (width * 0.5f + d)] would be correct. If the tangent was (0, 1, 0) then d would be 0 and the distance along n is no longer correct. How can I obtain the correct distance along n in all cases for the 6 dividing planes? Thank you.

1. 1
Rutin
19
2. 2
3. 3
JoeJ
15
4. 4
5. 5

• 21
• 19
• 11
• 13
• 17
• ### Forum Statistics

• Total Topics
631697
• Total Posts
3001763
×