# Position-Monitoring-Based Hybrid Routing Protocol for 3D UAV-Based Networks
## 3 Methods
### Selection of PHC
#### 3.3.3 Centroid PHC Selection  
The centroid approach selects a PHC-UAV based on the densities of all UAVs and the average paths of the whole network [46]. As demonstrated by the flowchart in Figure 1, this approach is used to find the center point of all UAVs in the network. We have calculated the centroid coordinates accordingly from Equation (14):  
\[X_{c}=\frac{\sum_{u=0}^{n}x_{n}}{n},\ Y_{c}=\frac{\sum_{u=0}^{n}y_{n}}{n},\ Z_{c}= \frac{\sum_{u=0}^{n}z_{n}}{n} \tag{14}\]  
The next step is to find the minimum distance from the centroid coordinates point and the nearest UAV from the minimum value function:  
\[f(X_{PHC},Y_{PHC},Z_{PHC})=\sum_{m=1}^{n}d_{m} \tag{15}\]  
Here, dm is a minimum distance of the PHC-UAV from the centroid point coordinates, and \(n\) is the maximum number of nearest UAVs. The above can be simplified as:  
\[f(X_{PHC},Y_{PHC},Z_{PHC})=\sqrt{(X_{m}-X_{C})+\ (Y_{m}-Y_{C})\ (Z_{m}-Z_{C})} \tag{16}\]  
From Equation (16), the nearest UAVs to the centroid point are selected as candidates for the PHC-UAV of the network. The two potential candidate UAVs having the closest distance to the centroid distance are selected. The next step is to choose the PHC-UAV that is nearest to (D\({}_{\text{C}}\)) point as the PHC-UAV node contains the highest power in terms of shortest paths and having connections across the network. Therefore, centrality measures are adopted to find the UAV closest to the D\({}_{\text{C}}\) point. The two key preferences utilize the degree of centrality of each UAV and the betweenness centrality of the UAVs to select the optimal PHC. The degree of centrality determines the number of neighboring UAVs connected to the PHC. An increase in connection makes the location information of all UAVs more accurate and can be calculated by Equation (17):  
\[Deg\Big{(}I_{th(UAV)}\Big{)}=\frac{\sum_{i=1}^{n}uav_{i,n-i}}{N-i} \tag{17}\]  
Here, Deg is the degree, the \(l\)th _UAV_ is the summation of all connections that are connected minus the total number of UAVs present in the network. The degree of centrality plays an important role in finding more connections and optimal paths. The other preference is betweenness centrality; as we know, the UAVs are distributed in a sparse nature; therefore, it is very important that PHC-UAV must be well connected with all UAVs. Equation (10) calculates the betweenness centrality, which is all shortest paths from \(l\)th UAV divided by all paths across the network:  
\[CB\Big{(}I_{lt(UAV)}\Big{)}=\sum_{i>n-1}\frac{P_{i}}{P_{N-i}} \tag{18}\]  
After finding two key measures, we have formulated the maximum utility function based on two key preferences. Based on Equation (19), the UAV attaining the highest utility value is selected, as primarily shown in Figure 3, which shows the PHC and neighboring UAVs. PHC-UAV contains the highest degree of centrality, and PHC-UAVit has the shortest paths of all other UAVs. The maximum utility can be evaluated as:  
\[U(I_{th(UAV)})=\sqrt{Deg\Big{(}I_{th(UAV)}\Big{)}*CB\Big{(}I_{it(UAV)}\Big{)}} \tag{19}\]  
where, \(U(I_{th(UAV)})>U(n-I_{th(UAV)})\). From the maximum value of the utility function, UAV is selected as the primary PHC-UAV, and the second highest maximum value can work as a secondary PHC. In case the primary PHC loses connection or is dead, the secondary UAV acts as a substitute PHC for the network. Figure 3 shows the PHC-UAV and other UAV nodes moving in a 3D environment. Algorithm 1 presents the pseudo-code of the selection of PHC in a UAV environment using the centroid approach. It starts from line 1, using the centroid function that takes N number of UAV nodes. Lines 2-4 execute a loop, where each UAV node updates its 3D positions according to 3 coordinator points (x,y,z) of the GPS. Line 5 calculates the centroid point (D\({}_{\text{C}}\)) based on Equations (7) and (8). Line 6 adds the ID of each UAV node with its calculated distance (dist) in the NL vector. Line 7 shows that if the NL vector is empty, it goes back to Line 5 for recalculation of the D\({}_{\text{C}}\) point.