/** * Returns the corners of the given bounding box in local coordinates. * * @param boundingBox The bounding box. * @return The corners of the bounding box in local coordinates. */ private static List<Point3d> getCorners(AxisAlignedBoundingBox3DFloat boundingBox) { final List<Point3d> corners = new ArrayList<>(); Translation lfb = boundingBox.getLeftFrontBottom(); Point3d leftFrontBottom = new Point3d(lfb.getX(), lfb.getY(), lfb.getZ()); for (boolean w : BOOLEAN_VALUES) { for (boolean d : BOOLEAN_VALUES) { for (boolean h : BOOLEAN_VALUES) { Point3d p = new Point3d(leftFrontBottom); if (w) { p.x += boundingBox.getWidth(); } if (d) { p.y += boundingBox.getDepth(); } if (h) { p.z += boundingBox.getHeight(); } corners.add(p); } } } return corners; }
/** * Gets the center coordinates of the unit's BoundingBox in the unit coordinate system as a Point3d object. * * @param unitConfig the unit config to refer the unit. * @return center coordinates of the unit's BoundingBox relative to unit * @throws NotAvailableException is thrown if the center can not be calculate. */ default Point3d getUnitBoundingBoxCenterPoint3d(final UnitConfig unitConfig) throws NotAvailableException { final AxisAlignedBoundingBox3DFloatType.AxisAlignedBoundingBox3DFloat bb = getUnitShape(unitConfig).getBoundingBox(); final TranslationType.Translation lfc = bb.getLeftFrontBottom(); final Point3d center = new Point3d(bb.getWidth(), bb.getDepth(), bb.getHeight()); center.scale(0.5); center.add(new Point3d(lfc.getX(), lfc.getY(), lfc.getZ())); return center; }
public BoundingBox(Transform3D fromUnitCoordinateToRootCoordinateTransform, AxisAlignedBoundingBox3DFloat box) { setDimensions(box.getWidth(), box.getDepth(), box.getHeight()); Transform3D lfb = toTransform(toVector(box.getLeftFrontBottom())); forwardTransform = new Transform3D(fromUnitCoordinateToRootCoordinateTransform); forwardTransform.mul(lfb); setForwardTransform(forwardTransform); calculateCenters(); }