## 2 Materials and Methods
### Cropping and Alignment  
The second stage of the process fulfills two tasks: it reduces the number of points to process by clipping those outside the region of interest (ROI), and it transforms the points by aligning the scan to a global reference frame via rotation. Due to the uneven terrain on which the robot moves, the relative position of the LIDAR to the ground changes for each scan, and the rotation angles must be calculated at each step.  
Those goals are achieved in three steps: first, distant points are removed; then, the position of the ground is estimated; finally, the rotation matrix is calculated to align the ground with the horizontal plane, and the scan points are rotated accordingly.  
The position of the ground plane is estimated using the Random Sample Consensus (RANSAC) method. The method detects the predefined shapes based on the hypotheses generated by random sampling of the dataset. Hypotheses are then accepted or rejected by a vote mechanism involving all remaining data samples. The method was developed by [PERSON] and [PERSON] [40] and was later modified to increase its applicability and efficiency. In [41], a version of the RANSAC algorithm was proposed to effectively detect several basic shapes, such as planes, spheres, cylinders, cones, and tori. The method was successfully applied in a similar scenario of ground detection with 3D LIDAR in industrial environment in [42]. A review of the state-of-the-art developments in the RANSAC algorithm and its variants for robotic applications is presented in [43].  
In the proposed workflow, the ground plane \(\pi_{G}\) is calculated using the implementation of the RANSAC algorithm from the PCL library [44]. The points are matched to the ground plane represented by the four-parameter pc1::SACMODEL_PLANE model, equivalent to the Hessian normal form  
\[\pi_{G}:\ n_{x}x+n_{y}y+n_{z}z+n_{0}=0, \tag{3}\]  
where \(n_{G}=(n_{x},n_{y},n_{z})^{T}\) is a vector normal to the plane and \(n_{0}\) a distance between the plane and the sensor origin.  
Based on the parameters obtained for the ground plane, the points within a predefined minimum distance from the ground \(d_{gmin}\) are excluded. The remaining points are then rotated and translated to align the ground and XY planes  
\[P^{A}=R(n_{G})P^{C}-(0,0,n_{0})^{T}. \tag{4}\]  
The \(3\times 3\) rotation matrix \(R(n_{G})\) is obtained from the Rodrigues formula.  
\[R(n_{G})=\cos\alpha id_{3}+(1-\cos\alpha)vv^{T}+\sin\alpha[v], \tag{5}\]  
where \(id_{3}\) denotes \(3\times 3\) identity matrix and \([v]\) is an antisymmetric matrix generated from \(v=(v_{x},v_{y},v_{z})^{T}\) as  
\[[v]=\begin{pmatrix}0&-v_{z}&v_{y}\\ v_{z}&0&-v_{x}\\ -v_{y}&v_{x}&0\end{pmatrix}. \tag{6}\]The rotation axis \(v\) is obtained from a vector product of the vector normal to the ground plane \(n_{G}\) and the unit vector parallel to the sensor Z axis, and the rotation angle \(\alpha\) is obtained from the scalar product of the two:  
\[v=n_{g}\times(0,0,1)^{T},\qquad\alpha=\arccos\Big{\langle}n_{g},(0,0,1)^{T} \Big{\rangle}. \tag{7}\]  
An example of transformation results in each step is presented in Section 3.2. The results of the cropping and alignment stage can be modified by tuning the distance to the ground \(d_{gmin}\).