The image below illustrates the example, when using OBB is better than AABB. @figure{/user_guides/modeling_data/images/modeling_data_image015.png,"Illustrating the problem with AABB.",320} AABBs in this picture are interfered. Therefore, many OCCT algorithms will spend much time to interfere the shapes. However, if we check OBBs, which are not interfered, then searching of interferences between the shapes will not be necessary. At that, creation and analysis of OBBs takes significantly more time than the analogical operations with AABB. Later in this section, the bounding boxes having the smallest surface area will be called *optimal*. In OCCT, bounding boxes are defined in *Bnd* package. *Bnd_Box* class defines AABB, *Bnd_OBB* class defines OBB. These classes contain the following common methods (this list is not complete; see the documentation about the corresponding class for detailed information): - *IsVoid* method indicates whether the bounding box is empty (uninitialized). - *SetVoid* method clears the existing bounding box. - *Enlarge(...)* extends the current bounding box. - *Add(...)* extends the bounding box as necessary to include the object (a point, a shape, etc.) passed as the argument. - *IsOut(...)* checks whether the argument is inside/outside of the current BndBox. BRepBndLib class contains methods for creation of bounding boxes (both AABB and OBB) from the shapes. @subsection occt_modat_6_1 Brief description of some algorithms working with OBB @subsubsection occt_modat_6_1_1 Creation of OBB from set of points The algorithm is described in "Fast Computation of Tight Fitting Oriented Bounding Boxes" by Thomas Larsson and Linus Källberg. It includes the following steps: 1. Choose \f$N_{a} (N_{a} \geq 3) \f$ initial axes.
2. Project every given point to the every chosen (in item 1) axis. At that, "minimal" and "maximal" points of every axis (i.e. point having minimal and maximal parameter (correspondingly) of the projection to this axis) are chosen. I.e. \f$2*N_{a} \f$ points will be held and this set can contain equal points. Later (unless otherwise specified) in this algorithm we will work with these \f$2*N_{a} \f$ points only.
3. Choose one pair of points among all pairs of "minimal" and "maximal" points of every axis (from item 1), with two furthest points. Let \f$p_{0} \f$ and \f$p_{1} \f$ be the "minimal" and "maximal" point of this pair.
4. Create an axis \f$\mathbf{e_{0}}\left \{ \overrightarrow{p_{0}p_{1}} \right \} \f$ (i.e. having direction \f$\overrightarrow{p_{0}p_{1}} \f$ ).
5. Choose the point \f$p_{2} \f$ (from the set defined in item 2) which is in the maximal distance from the infinite line directed along \f$\mathbf{e_{0}} \f$ axis.
Further, let us consider the triangle \f$T_{0}\left \langle p_{0}, p_{1}, p_{2} \right \rangle \f$ (i.e. having vertices \f$p_{0}, p_{1} \f$ and \f$p_{2} \f$). Namely: 6. Create new axes: \f$\mathbf{e_{1}}\left \{ \overrightarrow{p_{1}p_{2}} \right \} \f$, \f$\mathbf{e_{2}}\left \{ \overrightarrow{p_{2}p_{0}} \right \} \f$, \f$\mathbf{n}\left \{ \overrightarrow{\mathbf{e_{0}}} \times \overrightarrow{\mathbf{e_{1}}} \right \} \f$, \f$\mathbf{m_{0}}\left \{ \overrightarrow{\mathbf{e_{0}}} \times \overrightarrow{\mathbf{n}} \right \} \f$, \f$\mathbf{m_{1}}\left \{ \overrightarrow{\mathbf{e_{1}}} \times \overrightarrow{\mathbf{n}} \right \} \f$, \f$\mathbf{m_{2}}\left \{ \overrightarrow{\mathbf{e_{2}}} \times \overrightarrow{\mathbf{n}} \right \} \f$.
7. Create OBBs based on the following axis: \f$\left \{ \mathbf{e_{0}} \vdots \mathbf{m_{0}} \vdots \mathbf{n} \right \} \f$, \f$\left \{ \mathbf{e_{1}} \vdots \mathbf{m_{1}} \vdots \mathbf{n} \right \} \f$ and \f$\left \{ \mathbf{e_{2}} \vdots \mathbf{m_{2}} \vdots \mathbf{n} \right \} \f$ . Choose optimal OBB.
8. Choose the points \f$q_{0} \f$ and \f$q_{1} \f$ (from the set defined in item 2), which are in maximal distance from the plane of the triangle \f$T_{0} \f$ (from both sides of this plane). At that, \f$q_{0} \f$ has minimal coordinate along the axis \f$\mathbf{n} \f$, \f$q_{1} \f$ has a maximal coordinate.
9. Repeat the step 6...7 for the triangles \f$T_{1}\left \langle p_{0}, p_{1}, q_{0} \right \rangle \f$, \f$T_{2}\left \langle p_{1}, p_{2}, q_{0} \right \rangle \f$, \f$T_{3}\left \langle p_{0}, p_{2}, q_{0} \right \rangle \f$, \f$T_{4}\left \langle p_{0}, p_{1}, q_{1} \right \rangle \f$, \f$T_{5}\left \langle p_{1}, p_{2}, q_{1} \right \rangle \f$, \f$T_{6}\left \langle p_{0}, p_{2}, q_{1} \right \rangle \f$.
The algorithm of analyzing axis \f$\mathbf{l} \f$ is following: 1. Compute the "length" according to the formula: \f$L_{j}=\sum_{i=0}^{2}{H_{i}\cdot \left | \overrightarrow{\mathbf{a_{i}}} \cdot \overrightarrow{\mathbf{l}} \right |} \f$. Here, \f$\mathbf{a_{i}} \f$ is an i-th axis (X-axis, Y-axis, Z-axis) of j-th BndBox (j=1...2). \f$H_{i} \f$ is a half-dimension along i-th axis. 2. If \f$\left |\overrightarrow{C_{1}C_{2}} \cdot \overrightarrow{\mathbf{l}} \right | > L_{1}+L_{2} \f$ (where \f$C_{j} \f$ is the center of j-th OBB) then the considered OBBs are not interfered in terms of the axis \f$\mathbf{l} \f$. If OBBs are not interfered in terms of at least one axis (of 15) then they are not interfered at all. @subsubsection occt_modat_6_1_5 Method Add for point or another bounding box Create a new OBB (see the section @ref occt_modat_6_1_1) based on the source point and all vertices of the given bounding boxes. @subsection occt_modat_6_2 Add a shape Method *BRepBndLib::AddOBB(...)* allows creating the bounding box from a complex object *(TopoDS_Shape)*. This method uses both algorithms described in the sections @ref occt_modat_6_1_1 and sections @ref occt_modat_6_1_2. The first algorithm is used if the outer shell of the shape can be represented by a set of points contained in it. Namely, only the following elements are the source of set of points: - Nodes of triangulation; - Nodes of *Poly_Polygon3D*; - Vertices of edges with a linear 3D-curve lying in the planar face; - Vertices of edges with a linear 3D-curve if the source shape does not contain a more complex topological structure (e.g. the source shape is a compound of edges); - Vertices if the source shape does not contain a more complex topological structure (e.g. the source shape is a compound of vertices). If the required set of points cannot be extracted then the algorithm from section @ref occt_modat_6_1_2 is used for OBB creation. The package *BRepBndLib* contains methods *BRepBndLib::Add(...), BRepBndLib::AddClose(...)* and *BRepBndLib::AddOptimal(...)* for creation of AABB of a shape. See the reference manual for the detailed information. @subsection occt_modat_6_3 Limitations of algorithm for OBB creation. 1. The algorithm described in the section @ref occt_modat_6_1_1 works significantly better (finds resulting OBB with less surface area) and faster than the algorithm from the section @ref occt_modat_6_1_2. Nevertheless, (in general) the result returned by both algorithms is not always optimal (i.e. sometimes another OBB exists with a smaller surface area). Moreover, the first method does not allow computing OBBs of shapes with a complex geometry. 2. Currently, the algorithm of OBB creation is implemented for objects in 3D space only.