2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
8 package eu.svjatoslav.sixth.e3d.geometry;
11 * Same as: 3D rectangle, rectangular box, rectangular parallelopiped, cuboid,
12 * rhumboid, hexahedron, rectangular prism.
14 public class Box implements Cloneable {
16 public final Point3D p1;
17 public final Point3D p2;
24 public Box(final Point3D p1, final Point3D p2) {
29 public Box addBorder(final double border) {
32 p1.translateX(-border);
33 p2.translateX(border);
35 p1.translateX(border);
36 p2.translateX(-border);
40 p1.translateY(-border);
41 p2.translateY(border);
43 p1.translateY(border);
44 p2.translateY(-border);
48 p1.translateZ(-border);
49 p2.translateZ(border);
51 p1.translateZ(border);
52 p2.translateZ(-border);
60 return new Box(p1.clone(), p2.clone());
63 public double getDepth() {
64 return Math.abs(p1.z - p2.z);
67 public double getHeight() {
68 return Math.abs(p1.y - p2.y);
71 public double getWidth() {
72 return Math.abs(p1.x - p2.x);
75 public void setSizeCentered(final Point3D size) {
76 p2.clone(size).scaleDown(2);
77 p1.clone(p2).invert();