Package eu.svjatoslav.sixth.e3d.geometry
Class Box
java.lang.Object
eu.svjatoslav.sixth.e3d.geometry.Box
- All Implemented Interfaces:
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Creates a copy of this box with cloned corner points.enlarge(double border) Enlarges the box by the specified border in all directions.doublegetDepth()Returns the depth of the box (distance along the Z-axis).doubleReturns the height of the box (distance along the Y-axis).doublegetWidth()Returns the width of the box (distance along the X-axis).voidsetBoxSize(Point3D size) Sets the size of the box.
-
Field Details
-
p1
The first corner point of the box. -
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
Creates a new box with the specified corner points.- Parameters:
p1- the first corner pointp2- the second corner point (opposite corner)
-
-
Method Details
-
enlarge
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
Creates a copy of this box with cloned corner points. -
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
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-Point3Dspecifies box size in x, y and z axis.
-