# A Coal Mine Excavation Tunnels Modeling Method Based on Point Clouds
## 3 Methods  
### Point Cloud Coordinate Transformation  
The initial coordinate system of the tunnel is determined during the initialization of the point cloud acquisition device, and the tunnel's direction has inherent uncertainty, which increases the complexity and computational effort required for point cloud processing. By aligning the tunnel direction with the Y-axis, the point cloud processing algorithm can be simplified, significantly reducing computational complexity and improving processing efficiency. In this study, we transform the tunnel coordinate system to align with the Y-axis. The main steps of the transformation, including centroid translation and alignment with X-Y-Z-axis, are shown in Figure 3.  
1. Translation of the tunnel centroid to the origin of the coordinate system The centroid of the point cloud \((X_{c},Y_{c},Z_{c})\) is calculated as \[X_{c}=\frac{1}{n}\sum_{n}x_{i},Y_{c}=\frac{1}{n}\sum_{n}y_{i},Z_{c}=\frac{1}{n }\sum_{n}z_{i}\] (1) where \(n\) is the number of points. The translation vector is defined as \(\mathbf{t}=[-X_{c},-Y_{c},-Z_{c}]\), and this translation moves the centroid of the point cloud to the origin of the coordinate system. 2. Calculation of the tunnel direction and alignment with the Y-axis In principal component analysis (PCA), the first principal component corresponds to the direction of maximum variance in the dataset, which can be used to identify the tunnel direction in the point cloud. Therefore, the tunnel direction can be calculated by computing  
Figure 3: Pipeline of coordinate transformation. the principal components of the point cloud. This process involves first calculating the covariance matrix of the point cloud, where the point cloud is represented as matrix X, with each row corresponding to the coordinates of a point. The covariance matrix \(\theta\) is calculated as  
\[\theta=\frac{1}{n-1}X^{T}X \tag{2}\]  
Eigen decomposition is then applied to the covariance matrix to obtain the eigenvalues and their corresponding eigenvectors. The eigenvector \(\overset{\rightarrow}{p}(x_{0},y_{0},z_{0})\) corresponding to the largest eigenvalue represents the tunnel direction. The rotation matrix of the point cloud is determined based on the tunnel direction, which involves calculating the rotation angles along the Z-axis and X-axis. The tunnel is firstly rotated around the Z-axis to align with the YOZ plane. Then, it is rotated around the X-axis secondly and Y-axis thirdly to align the tunnel direction with the Y-axis, as illustrated in Figure 4.  
The rotation angles and rotation matrices of the point cloud around the Z-axis and X-axis according to \(\overset{\rightarrow}{p}(x_{0},y_{0},z_{0})\) are as follows. \[\theta_{z}=\arctan\left(\frac{x_{0}}{y_{0}}\right)\]  
\[\theta_{x}=-\arctan\left(\frac{z_{0}}{\sqrt{x_{0}^{2}+y_{0}^{2}}}\right)\]  
\[matrix^{Z}= \begin{bmatrix}\cos(\theta_{z})&-\sin(\theta_{z})&0\\ \sin(\theta_{z})&\cos(\theta_{z})&0\\ 0&0&1\end{bmatrix}  \tag{3}\]  
\[matrix^{X}= \begin{bmatrix}1&0&0\\ 0&\cos(\theta_{x})&-\sin(\theta_{x})\\ 0&\sin(\theta_{x})&\cos(\theta_{x})\end{bmatrix} \]
3. Calculation of the rotation angle and alignment with X-axis and Z-axis  
After aligning the tunnel direction with the Y-axis, the top and bottom surfaces of the tunnel may not be parallel to the XOY plane, as shown in Figure 5a. To correct this, the rotation angle \(\theta_{y}\) around the Y-axis needs to be determined for the point cloud. A series of slices \(\{Si\}\) is taken along the tunnel direction (Y-axis), and the minimum bounding rectangle (MBR) \(\{mbr_{i}\}\) for each slice is calculated, as shown in the red rectangle in Figure 5b. The minimum bounding rectangle can be calculated using the rotating calipers algorithm [44]. First, the convex hull of the point set is identified, which forms the boundary of the rectangle. This step can be achieved using algorithms such as Graham scan [45] or Jarvis March [46].