java.lang.Object
eu.svjatoslav.sixth.e3d.geometry.Box
All Implemented Interfaces:
Cloneable

public class Box extends Object implements Cloneable
A 3D axis-aligned bounding box defined by two corner points.

Also known as: 3D rectangle, rectangular box, rectangular parallelepiped, cuboid, rhomboid, hexahedron, or rectangular prism.

The box is defined by two points (p1 and p2) that represent opposite corners. The box does not enforce ordering of these points.

Example usage:


 Box box = new Box(new Point3D(0, 0, 0), new Point3D(100, 50, 200));
 double volume = box.getWidth() * box.getHeight() * box.getDepth();
 box.enlarge(10);  // expand by 10 units in all directions
 
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final Point3D
    The first corner point of the box.
    final Point3D
    The second corner point of the box (opposite corner from p1).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Box()
    Creates a new box with both corner points at the origin.
    Box(Point3D p1, Point3D p2)
    Creates a new box with the specified corner points.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a copy of this box with cloned corner points.
    enlarge(double border)
    Enlarges the box by the specified border in all directions.
    double
    Returns the depth of the box (distance along the Z-axis).
    double
    Returns the height of the box (distance along the Y-axis).
    double
    Returns the width of the box (distance along the X-axis).
    void
    Sets the size of the box.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • p1

      public final Point3D p1
      The first corner point of the box.
    • p2

      public final Point3D p2
      The second corner point of the box (opposite corner from p1).
  • Constructor Details

    • Box

      public Box()
      Creates a new box with both corner points at the origin.
    • Box

      public Box(Point3D p1, Point3D p2)
      Creates a new box with the specified corner points.
      Parameters:
      p1 - the first corner point
      p2 - the second corner point (opposite corner)
  • Method Details

    • enlarge

      public Box enlarge(double border)
      Enlarges the box by the specified border in all directions.
      Parameters:
      border - The border to enlarge the box by. If the border is negative, the box will be shrunk.
      Returns:
      The current box.
    • clone

      public Box clone()
      Creates a copy of this box with cloned corner points.
      Overrides:
      clone in class Object
      Returns:
      a new box with the same corner coordinates
    • getDepth

      public double getDepth()
      Returns the depth of the box (distance along the Z-axis).
      Returns:
      the depth (always positive)
    • getHeight

      public double getHeight()
      Returns the height of the box (distance along the Y-axis).
      Returns:
      the height (always positive)
    • getWidth

      public double getWidth()
      Returns the width of the box (distance along the X-axis).
      Returns:
      the width (always positive)
    • setBoxSize

      public void setBoxSize(Point3D size)
      Sets the size of the box. The box will be centered at the origin. Previous size and position of the box will be lost.
      Parameters:
      size - Point3D specifies box size in x, y and z axis.