Automated Solving Algorithm and Application for Oriented Bounding Box Based on Principal Axis of Inertia

In mechanical design and manufacture, the minimum size of raw material of each part should be measured before processing. Generally, this size could be equal to the size of minimum bounding box. When the assembled parts of a product reach an enormous quantity, the measurement would be a rough work. This paper introduced an automated solving algorithm for the oriented bounding box based on principal axis of inertia, combined with CATIA structural tree recursive traversal algorithm according to CAA V5 Automation API, to implement an automated solution of the engineering acceptable minimum oriented bounding box of CATIA model.


Introduction
Bounding box is an algorithm for obtaining an optimal bounding space of a discrete point set, its basic idea is to use larger but simple geometry such as sphere and cuboid to approximate an object having complex geometry. The general algorithms of bounding box include bounding sphere [1,2], aligned-axis bounding box (AABB) [3,4], oriented bounding box (OBB) [5][6][7], fixed directions hulls (FDH) [8], discrete orientation polytopes (k-DOP) [9,10], etc., they are widely applied in collision detection, mold design, product packaging design, picture processing and pattern recognition field.
Among these popular bounding box algorithms, the bounding sphere was more efficient with less accuracy, it was usually used for the initial processing of objects in collision detection, and hence the following processing was accomplished by cuboid bounding box algorithms. Among the cuboid bounding box algorithms, AABB was relatively uncomplicated, it was a bounding box with each face parallel to the three planes of the spatial absolute coordinate system, so it could not be considered as the optimal minimum bounding box. OBB was a bounding box with higher accuracy to approximate an object compared with the bounding sphere and the AABB, it could be rotated arbitrarily according to the first moment of the object, and therefore the OBB with an appropriate direction matrix could be deemed as the optimal minimum bounding box for a geometric object.
The 3D modeling software, CATIA V5's Generative Shape Design module provided two functions including Creates Rough Stock and Bounding Box to obtain the OBB of an object manually. The two functions were commonly regarded as the accurate and valid method to obtain the minimum oriented bounding box. However, they were only operated through manually selecting a plane, a line or a set of axes to be the reference of OBB's first moment, and it was unable to recognize the reference automatically. Meanwhile, it depended on the experience of user to select the appropriate plane, line or axes, therefore the OBB obtained by Creates Rough Stock or Bounding Box was not always the optimal minimum one. In addition, CAA V5 Automation did not provide any API for above functions, IOP Publishing doi:10.1088/1742-6596/2101/1/012007 2 which led to no possibility to invoke the two functions. On account of the above two problems, it became a difficulty to measure the minimum bounding box of a large number of geometric objects automatically.
This article proposed an algorithm for the OBB based on principal axis of inertia (IPA OBB) combined with CATIA structural tree recursive traversal algorithm according to CAA V5 Automation API, to implement an automated solution of the engineering acceptable minimum oriented bounding box of CATIA model successfully.

Principal Axis of Inertia
For a static rigid body, its principal axis of inertia is defined as the coordinate axis corresponding to the inertia matrix when the product of inertia of its inertia matrix is zero. The inertia tensor ‫ܣ‬ could be described as equation (1). ‫ܣ‬ contained three moments of inertia and six products of inertia of a rigid body coordinate system with an arbitrary point as the origin.
‫ܣ‬ was a real symmetric matrix in equation (1) where To calculate the six products of inertia, a spherical coordinate system that had a common origin with the rectangular coordinate system was introduced. In order to complete the matrix transformation, ‫ݔ‬ = ‫ݎ‬ sin ߮ cos ߠ, ‫ݕ‬ = ‫ݎ‬ sin ߮ sin ߠ, ‫ݖ‬ = ‫ݎ‬ cos ߮ were established. ‫,ݎ(ߩ‬ ߠ, ߮) was the mass density function.
Then equation (2) was obtained according to the definition of inertia coefficient [11].
It could be proved that there was only one principal axis of inertia passing through the gravity center of the rigid body [12]. Besides, because the principal axis of inertia was a real symmetric matrix, it could conduct a diagonalization of matrix, solution of eigenvalues and eigenvectors to simplify the integration operation. The calculated eigenvectors after unit orthogonalization were the three directions of the principal axis of inertia.

Automated Solving Algorithm for OBB
OBB was initially applied in light-tracking, fitting tightly around enclosed objects. The arbitrariness of direction allowed OBB to surround a geometric object as much as possible according to the shape characteristics of the surrounded object. When the geometric object occurred a movement, the OBB could be recalculated by performing a corresponding coordinate transformation on its basic axis.
The first-order and second-order statistical characteristics of the vertex coordinates of geometric objects could be used to divide the OBB's level, as shown in equation (3), (4), (5) [13].
where n was the number of triangle segments which made up the model. ‫‬ , ‫ݍ‬ , ‫ݎ‬ were all matrices and ‫ܥ‬ ୨୩ were both 3×3 covariance matrices. μ was the average. C was the covariance. The coordinate of the three vertices of the i-th triangle was ൫‫‬ , ‫ݍ‬ , ‫ݎ‬ ൯. Principal component analysis (PCA) is a mainstay of modern data analysis [14,15] to transform a set of potentially related variables into a set of linearly unrelated variables through orthogonal transformation. Meantime, PCA is also a prevailing method to solve the OBB for a limited discrete point set. A rigid body could be regarded as an unlimited discrete point set. In PCA, covariance and covariance matrix are two important concepts. Covariance could describe the degree of linear correlation between two variables, as shown in equation (6) where ߤ and ߤ were the expected value of ܺ and ܺ respectively. Therefore, the 3×3 covariance matrix in equation (4) could be introduced as ‫ܤ‬ as shown in equation (7).
This covariance matrix was also a real symmetric matrix which could be diagonalized and the eigenvectors corresponding to the eigenvalues were orthogonal mutually, it had the same characteristics as the principal axis of inertia from equation (1). The eigenvectors of the covariance matrix could express the directions of the principal axis of OBB. Considering there were several eigenvectors corresponding to the eigenvalues, the three direction vectors of the principal axis of inertia after unitization could be three of the appropriate solutions.
As concluded above, the principal axis of inertia of a geometric object could be established as the basic axis system to calculate the IPA OBB.
CAA V5 Automation offered API for measuring the principal axis of inertia of an object, obtaining the extremum in a direction as well. It provided the conditions to implement the algorithm of IPA OBB. Hence the solving algorithm of IPA OBB was presented as a flow chart in figure 1.
In mechanical design and manufacture, a product usually contained a plenty of sub parts. Therefore, the algorithm of IPA OBB was combined with CATIA structural tree recursive traversal algorithm to traverse a CATIA model, to carry out the purpose of automated solving the oriented bounding box of each part automatically. The CATIA structural tree recursive traversal algorithm containing IPA OBB calculating processes was presented as a flow chart in figure 2.

Algorithm Implementation and Application
According to the solving process as shown above, the algorithm was implemented under the environment of Window 7 with Xeon (R) CPU E3-1225 V5 3.30 GHz, 16.0 GB memory, Visual Basic 6.0, CATIA V5 R18 and invoking CAA V5 Automation API.
For a CATIA Product containing many sub products and sub parts, the IPA OBB solving process should be only operated in each CATPart document excluding all CATProduct documents. The CATIA structural tree recursive traversal algorithm could achieve above requirement by judging the type of the retrieved document in the tree.
The automated solving algorithm was applied in a CATIA model of mold which was shown in figure 3. This mold contained three CATProduct documents and eighteen CATPart documents with different serial numbers. In order to better evaluate the accuracy of the OBB size calculated by IPA OBB algorithm, the result of IPA OBB size was compared with the AABB size and the OBB size calculated by Creates Rough Stock (CRS OBB). The referenced direction of axis of CRS OBB was a plane manually selected from each object. The die surface, the deckle board and the cushion were selected as examples for application. Their AABBs, CRS OBBs and IPA OBBs were shown in figure 4 respectively. It could be concluded from figure 4 that the IPA OBBs of the die surface, the deckle board and the cushion approximated their CRS OBBs. Whereas the AABB presented more deviation from the shape of the part. Due to each face of the AABB was parallel to the three mutually perpendicular planes (plane XY, YZ, XZ) of the spatial absolute coordinate system, the size and the shape of AABB mainly depended on the measured object's position and attitude in the absolute coordinate system, leading to this inherent deviation. In case that an object had a relatively simple geometric shape, with a low average parallelism (might be described by dihedral angle) between each plane of the absolute coordinate system and each face of the object, this inherent deviation would tend to increase. When the object possessed a complex geometric shape, meanwhile it had a regular position and attitude in the absolute coordinate system, this inherent difference would tend to decrease instead. The cushion that possessed a simple shape with a random attitude in the absolute coordinate system in figure 4 belonged to the former situation. Since the referenced direction selected manually of a CRS OBB was not always the optimal solution, it might be a situation that the calculated result of IPA OBB was more accurate than that of CRS OBB.
In consideration of the CRS OBB with an appropriate direction to be as the optimal minimum bounding box generally, it would be valid to take the CRS OBB size as the standard to evaluate the accuracy and engineering acceptability of IPA OBB and AABB. In order to evaluate the specific differences between IPA OBB and AABB, the percentage of volume difference of IPA OBB and AABB compared with CRS OBB could be calculated by equation (8) and (9) and it was illustrated in In equation (9), σ was the percentage of volume difference of IPA OBB compared with CRS OBB, where ܸ was the volume of AABB and ܸ ோௌை was the volume of CRS OBB. In equation (10), σ ூை was the percentage of volume difference of IPA OBB compared with CRS OBB, where ܸ ூை was the volume of IPA OBB.
It could be analyzed from figure 5 that the values of σ were larger than the values of σ ூை mostly. Only the Mold-001-012 revealed a larger value of σ ூை of 23.44% which was even larger than its value of σ of 16.37%. The values of σ ூை of remaining parts were all below 3%. The average value of σ ூை was 1.57% and that of σ was 263.75%. In addition, the standard deviation of σ ூை was 22.57 which was much smaller than that of σ of 932.44, demonstrating the stability of the calculated results of IPA OBB.
In general, the low percentage of volume difference and low standard deviation of IPA OBB proved a high accuracy and engineering acceptability of the algorithm.

Conclusion
The algorithm for the oriented bounding box based on principal axis of inertia, which was named as IPA OBB algorithm, was proposed. The IPA OBB algorithm was combined with structural tree recursive traversal algorithm through the API provide by CAA V5 Automation, to implement the automated solution of the engineering acceptable minimum oriented bounding box of CATIA model. A CATIA model of mold was used as the experimental verification object, to accomplish the automated solution of the OBB of its sub parts. By taking the CRS OBB as the standard, the experimental result showed that the average percentage of volume difference and standard deviation of IPA OBB were 1.57% and 22.57 respectively, which were both much smaller than those of AABB. The result proved that the algorithm of IPA OBB possessed a prevailing accuracy and engineering acceptability. Moreover, the IPA OBB algorithm might be modified to determine the optimal rotated axis of an object. In mechanical engineering field, the optimal rotated axis of the object could ensure the safety during the rotational motion, for instance, motor rotation, tooling spin, etc.
In brief, the automated solving algorithm for IPA OBB possessed a high accuracy, and the potential value of engineering application.