2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.geometry;
8 * Same as: 3D rectangle, rectangular box, rectangular parallelopiped, cuboid,
9 * rhumboid, hexahedron, rectangular prism.
11 public class Box implements Cloneable {
13 public final Point3D p1;
14 public final Point3D p2;
21 public Box(final Point3D p1, final Point3D p2) {
26 public Box addBorder(final double border) {
29 p1.translateX(-border);
30 p2.translateX(border);
32 p1.translateX(border);
33 p2.translateX(-border);
37 p1.translateY(-border);
38 p2.translateY(border);
40 p1.translateY(border);
41 p2.translateY(-border);
45 p1.translateZ(-border);
46 p2.translateZ(border);
48 p1.translateZ(border);
49 p2.translateZ(-border);
57 return new Box(p1.clone(), p2.clone());
60 public double getDepth() {
61 return Math.abs(p1.z - p2.z);
64 public double getHeight() {
65 return Math.abs(p1.y - p2.y);
68 public double getWidth() {
69 return Math.abs(p1.x - p2.x);
72 public void setSizeCentered(final Point3D size) {
73 p2.clone(size).scaleDown(2);
74 p1.clone(p2).invert();