# Advanced Methods for Point Cloud Processing and Simplification
## 4 Correction of Initial Point Cloud Rotation
The sum of all local maxima found by the modified version of the connected component labeling algorithm with respect to small gaps, is expressed in the following equation:  
\[\sum h_{d}(k)=\sum_{n=1}^{L_{N}}\max(h_{d}(L=n))=0, \tag{6}\]  
where \(L_{N}\) is the count of found components in the index accumulator \(L\). Figure 7 describes \(k\)-th step of the algorithm, where \(\sum h_{d}(k)\) is estimated for one rotation given by the index \(k\). The histograms of the X and Y axes are shown in Figure 7a for the initial angle 0 degrees and for the angle 4.3 degrees in Figure 7b. This serves for a better illustration of different \(\sum h_{d}(k)\) values. The different local maxima are noticeable from the analysis of both histograms in Figure 7.  
The algorithm rotates the input point cloud by the angle of one rotation step \(s_{R}\) in the range \(R_{\varphi}(\varphi_{Rs},\varphi_{\text{Re}})\). We recommend using a smaller rotation step as 0.1 degrees for better resolution. The analyzed point cloud is firstly rotated to the start angle \(\varphi_{Rs}\). The rotation matrix of one iteration step \(R(s_{R})\) is then constructed. The sum of all local maxima is evaluated in each rotation step and the actual point cloud is multiplied by \(R(s_{R})\) until the end angle \(\varphi_{\text{Re}}\) is reached. Figure 7a gives a sum curve \(\sum h_{X}\) for the X-axis and Figure 7b for the Y-axis. In this example, the \(R_{\varphi}(0,8)\) and \(s_{R}=0.1\) are used. Positions of both maxima are somewhat different. The searched orientation angle \(\varphi[^{\circ}]\) is the average value of both maxima positions. For this example, the maximum for X-axis in Figure 8a is 3.5 degrees and the maximum for the Y-axis in Figure 8b is 4.7 degrees. Then, the orientation angle is \(\varphi[^{\circ}]\) = 4.1 degrees. Figure 9 shows the corrected point cloud from Figure 5 inclu  
Figure 6: X-axis histogram: (**a**) Original histogram; (**b**) Result of Equation (5) applied on this figure (**a**) with marked parts and their maxima. Figure 7: Histograms of the X and Y axes for a different angle of rotation: (**a**) Original angle of 0 degrees; (**b**) Angle of 4.3 degrees. The new histograms in Figure 9 are sharper and have several bigger local maxima in the X and Y axes in comparison to Figure 5. The histogram in the Z-axis is the same. The range of the rotation interval \(R_{\varphi}\) is not possible to select arbitrarily. When a point cloud is rotated in an angle of 90 degrees, then, the X-axis becomes the Y-axis. The universal solution is to determine the initial point cloud rotation as the 0 degrees and the rotation range \(R_{\varphi}=\pm 45\) degrees. This algorithm is also fast because it uses a classical histogram, which its ways depend on the number of steps. The algorithm estimated the rotation angle \(\varphi_{o}\) in 10 ms for the used range of angles \(R_{\varphi}\). As was mentioned above, this algorithm allows the finding of the point cloud rotation of one coordinate axis from the other two. The assumptions for its success are the presence of flat surfaces, which is typically valid for indoor spaces.