Class CSGPlane

java.lang.Object
eu.svjatoslav.sixth.e3d.csg.CSGPlane

public class CSGPlane extends Object
Represents an infinite plane in 3D space using the Hesse normal form.

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 CSGPolygon faces
  • Split polygons that cross BSP partition boundaries
  • Determine which side of a BSP node a polygon lies on
See Also:
  • Field Details

    • EPSILON

      public static final double EPSILON
      Epsilon 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

      public Point3D 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 distance
      The 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

      public CSGPlane(Point3D normal, double distance)
      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

      public static CSGPlane fromPoints(Point3D a, Point3D b, Point3D c)
      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 plane
      b - the second point on the plane
      c - 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

      public CSGPlane clone()
      Creates a deep clone of this plane.

      The normal vector is cloned to avoid shared references.

      Overrides:
      clone in class Object
      Returns:
      a new CSGPlane with the same normal and distance
    • 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:

      1. Vertices on the front side become a new polygon (added to the front list)
      2. Vertices on the backside become a new polygon (added to the back list)
      3. Intersection points are computed and added to both polygons
      Parameters:
      polygon - the polygon to classify and potentially split
      coplanarFront - list to receive coplanar polygons with same-facing normals
      coplanarBack - list to receive coplanar polygons with opposite-facing normals
      front - list to receive polygons in the front half-space
      back - list to receive polygons in the back half-space