Class CSGPlane
A plane is defined by a normal vector (perpendicular to the plane surface)
and a scalar value 'w' representing the signed distance from the origin.
The plane equation is: normal.x * x + normal.y * y + normal.z * z = w
Planes are fundamental to BSP (Binary Space Partitioning) tree operations in CSG. They divide 3D space into two half-spaces:
- Front half-space: Points where
normal · point > w - Back half-space: Points where
normal · point < w
Planes are used to:
- Define the surface orientation of
CSGPolygonfaces - Split polygons that cross BSP partition boundaries
- Determine which side of a BSP node a polygon lies on
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Creates a deep clone of this plane.voidflip()Flips the plane orientation by negating the normal and distance.static CSGPlanefromPoints(Point3D a, Point3D b, Point3D c) Creates a plane from three non-collinear points.voidsplitPolygon(CSGPolygon polygon, List<CSGPolygon> coplanarFront, List<CSGPolygon> coplanarBack, List<CSGPolygon> front, List<CSGPolygon> back) Splits a polygon by this plane, classifying and potentially dividing it.
-
Field Details
-
EPSILON
public static final double EPSILONEpsilon value used for floating-point comparisons.When determining which side of a plane a point lies on, values within this threshold are considered coplanar (on the plane). This prevents numerical instability from causing infinite recursion or degenerate polygons during BSP operations.
- See Also:
-
normal
The unit normal vector perpendicular to the plane surface.The direction of the normal determines which side is "front" and which is "back". The front is the side the normal points toward.
-
distance
public double distanceThe signed distance from the origin to the plane along the normal.This is equivalent to the dot product of the normal with any point on the plane. For a plane defined by point P and normal N:
distance = N · P
-
-
Constructor Details
-
CSGPlane
Creates a plane with the given normal and distance.- Parameters:
normal- the unit normal vector (caller must ensure it's normalized)distance- the signed distance from origin to the plane
-
-
Method Details
-
fromPoints
Creates a plane from three non-collinear points.The plane passes through all three points. The normal is computed using the cross-product of vectors (b-a) and (c-a), then normalized. The winding order of the points determines the normal direction:
- Counter-clockwise (CCW) winding → normal points toward the viewer
- Clockwise (CW) winding → normal points away from the viewer
- Parameters:
a- the first point on the planeb- the second point on the planec- the third point on the plane- Returns:
- a new CSGPlane passing through the three points
- Throws:
ArithmeticException- if the points are collinear (cross-product is zero)
-
clone
Creates a deep clone of this plane.The normal vector is cloned to avoid shared references.
-
flip
public void flip()Flips the plane orientation by negating the normal and distance.This effectively swaps the front and back half-spaces. After flipping:
- Points that were in front are now in back
- Points that were in back are now in front
- Coplanar points remain coplanar
Used during CSG operations when inverting solids (converting "inside" to "outside" and vice versa).
-
splitPolygon
public void splitPolygon(CSGPolygon polygon, List<CSGPolygon> coplanarFront, List<CSGPolygon> coplanarBack, List<CSGPolygon> front, List<CSGPolygon> back) Splits a polygon by this plane, classifying and potentially dividing it.This is the core operation for BSP tree construction. The polygon is classified based on where its vertices lie relative to the plane:
Classification types:
- COPLANAR (0): All vertices lie on the plane (within EPSILON)
- FRONT (1): All vertices are in the front half-space
- BACK (2): All vertices are in the back half-space
- SPANNING (3): Vertices are on both sides (polygon crosses the plane)
Destination lists:
- coplanarFront: Coplanar polygons with same-facing normals
- coplanarBack: Coplanar polygons with opposite-facing normals
- front: Polygons entirely in front half-space
- back: Polygons entirely in back half-space
Spanning polygon handling:
When a polygon spans the plane, it is split into two polygons:
- Vertices on the front side become a new polygon (added to the front list)
- Vertices on the backside become a new polygon (added to the back list)
- Intersection points are computed and added to both polygons
- Parameters:
polygon- the polygon to classify and potentially splitcoplanarFront- list to receive coplanar polygons with same-facing normalscoplanarBack- list to receive coplanar polygons with opposite-facing normalsfront- list to receive polygons in the front half-spaceback- list to receive polygons in the back half-space
-