## 2 Method
With hav(\(\Theta\)) computed for the pair of points (A, B), \(d_{AB}\), which can be calculated using the inverse haversine function:  
\[\Theta=\text{archav}(\text{hav}(\Theta)). \tag{2}\]  
Finally \(d_{AB}\) can be calculated as  
\[d_{AB}=r\times\text{archav}(\text{hav}(\Theta)). \tag{3}\]  
With the closest point determined, it is possible to follow the track to define the target volume. This is carried out by selecting a point along the tracks in front of the train at a predefined distance, \(X\) m, which is the central point of the volume where obstacles will be searched. To define the target volume from the central search point in latitude-longitude coordinates, the GPS and LiDAR coordinate systems must first be aligned. To accomplish this, it is necessary to calculate the angle \(\theta\) between three GPS points (A, B, C), where A and B are the GPS points before and after the current GPS train coordinates, and C is the GPS central search point. A and B are used to define the train's bearing, and C is used to determine the orientation of the track line. The first required step is calculating the angle between the AB and BC lines, defined by their bearings, \(b_{AB}\) and \(b_{BC}\). The bearing of A from B (\(b_{AB}\)) is the angle measured in the clockwise direction from the north axis at point B, calculated as  
\[ \begin{split}\delta y&=\sin(\lambda_{B}-\lambda_{ A})\cdot\cos(\phi_{A})\\ \delta x&=\cos(\phi_{A})\cdot\sin(\phi_{B})-\sin( \phi_{A})\cdot\cos(\phi_{B})\cdot\cos(\lambda_{B}-\lambda_{A})\\ b_{AB}&=\text{arctan2}(\delta y,\delta x)\end{split}  \tag{4}\]  
where \(A=[\phi_{A},\lambda_{A}]\) and \(B=[\phi_{B},\lambda_{B}]\) are the latitude and longitude of points A and B, in radians, and \(b\) is the bearing of that direction relative to North. The bearing of B from C (\(b_{BC}\)) is calculated using the same process. After calculating the bearings \(b_{AB}\) and \(b_{BC}\), the difference between them is calculated, \(\theta=b_{BC}-b_{AB}\), which is the angle between the three GPS points (A, B, C). To transform the GPS coordinates points into the LiDAR coordinate system, we also need to obtain the distance (\(d\)) between the train's point (\(O\)) and the central search point (\(C\)) in GPS coordinates, using once again the Haversine formula (1). With this distance and the \(\theta\) angle, the difference between bearing calculated before, we can finally obtain the (x, y) point, \(C_{(x,y)}\), in the LiDAR coordinate system that corresponds to the central search point; see Equation (6). \[ \begin{split} C_{x}&=d\cdot\cos(\theta)\\ C_{y}&=d\cdot\sin(\theta)\end{split}  \tag{5}\]  
Because the LiDAR is not centered inside the locomotive, it is necessary to calibrate its positioning. After the LiDAR is installed, an acquisition is performed, and a point located on the tracks' central axis (\(T_{(x,y,z)}\)) is determined to be used as the search's origin. Its coordinates and associated rotations are then saved in the configuration file. This calibration is then applied to correct the central search point's coordinates (\(C^{\prime}_{(x,y,z)}\)), followed by determining its altitude, i.e., its \(z\) coordinate. \[ \begin{split} C^{\prime}_{x}&=C_{x}\\ C^{\prime}_{y}&=C_{y}-T_{y}\\ C^{\prime}_{z}&=C_{x}\cdot\frac{T_{z}}{T_{x}}\end{split}  \tag{6}\]With the central search point in the LiDAR coordinate system, \(C^{\prime}_{(x,y,z)}\), the next step is to determine if this point is inside the field of view (FOV) of the LiDAR (Figures 4 and 5). With this, only relevant data are processed, meaning data directly on the train path and inside the FOV, which enables a more efficient search on curved train paths by avoiding redundant operations. Consequently, this also speeds up data processing. If the point is inside the FOV, a configurable search area centered around it is defined and used to detect obstacles.