Class Plane

java.lang.Object
eu.svjatoslav.sixth.e3d.geometry.Plane

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

Planes are fundamental to BSP (Binary Space Partitioning) tree operations in CSG. They divide 3D space into two half-spaces.

See Also:
  • Field Details

    • EPSILON

      public static final double EPSILON
      Epsilon value used for floating-point comparisons in BSP operations. Smaller values provide higher precision but may cause issues with near-coplanar polygons. 1e-5 is a good balance for most 3D geometry.
      See Also:
    • normal

      public Point3D normal
      The unit normal vector perpendicular to the plane surface.
    • distance

      public double distance
      The signed distance from the origin to the plane along the normal.
  • Constructor Details

    • Plane

      public Plane(Point3D normal, double distance)
      Creates a plane with the given normal and distance.
      Parameters:
      normal - the unit normal vector
      distance - the signed distance from origin to the plane
  • Method Details

    • computeNormal

      public static boolean computeNormal(Point3D a, Point3D b, Point3D c, Point3D result)
      Computes the unit normal vector for a triangle defined by three points.

      Zero-allocation method: fills the result point instead of creating a new one. This is the shared implementation used by both fromPoints(Point3D, Point3D, Point3D) and SolidPolygon for shading calculations.

      The normal is computed as the cross product of two edge vectors (b-a and c-a), then normalized to unit length.

      Parameters:
      a - first point (base point for edge vectors)
      b - second point
      c - third point
      result - Point3D to receive the unit normal vector (modified in place)
      Returns:
      true if normal computed successfully, false if points are collinear (cross product magnitude less than EPSILON)
    • fromPoints

      public static Plane fromPoints(Point3D a, Point3D b, Point3D c)
      Creates a plane from three non-collinear points.

      Uses computeNormal(Point3D, Point3D, Point3D, Point3D) for the normal calculation, then computes the signed distance from origin using the dot product.

      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 Plane passing through the three points
      Throws:
      ArithmeticException - if the points are collinear (cannot define a plane)
    • clone

      public Plane clone()
      Creates a deep clone of this plane.
      Overrides:
      clone in class Object
      Returns:
      a new Plane with the same normal and distance
    • flip

      public void flip()
      Flips the plane orientation by negating the normal and distance.
    • splitPolygon

      public void splitPolygon(SolidPolygon polygon, List<SolidPolygon> coplanarFront, List<SolidPolygon> coplanarBack, List<SolidPolygon> front, List<SolidPolygon> back)
      Splits a polygon by this plane, classifying and potentially dividing it.
      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