## 3 DI-distributed Localization (DIL) Algorithm
### Distance Measurement
\[y=atan\theta+k \tag{3}\]  
where \(k\) is a constant, which is obtained by substituting location of the anchor node. \[k=y_{a}-x_{a}tan\theta \tag{4}\]  
Taking communication range of a beacon node as a uniform circular disc, Equation (5) can be obtained as follows. \[(x-x_{1})^{2}+(y-y_{1})^{2}=d_{1}^{2} \tag{5}\]  
Substituting Equation (3) in Equation (5) and upon simplification, Equation (6) can be obtained. \[(1+tan^{2}\theta)x^{2}-(2x_{1}+2y_{1}tan\theta-2 ktan\theta)x+R=0 \tag{6}\]  
where, \(R\) is  
\[R=x_{1}^{2}+k^{2}-2 ky_{1}+y_{1}^{2}-d_{1}^{2} \tag{7}\]  
Since Equation (6) is a simple quadratic equation, \(x\) coordinate of the location of the normal node can be calculated easily. Now \(y\) coordinate of the location can be obtained by substituting value of \(x\) in Equation (3). However, it could be possible that a normal node may receive beacon packets from two or more beacon nodes. It is to be noted that each normal node can have at least one beacon node within its communication range as per our assumptions. As described previously, first a normal node listens to the network and checks the arrival of the beacon packets. Normal node continues to wait for \(T_{n}\) units and maintains a coordinate table as shown in Table 1 to record the beacon packet's information. Each normal node maintains the coordinate table with four fields. They are the ID, location and RSSI value of the beacon nodes from which beacon packets are received. Besides, the last column of the table records the possible estimated location (P-Loc) information of the normal node. Normally, a normal node computes the possible location (P-Loc) from all of its received data as soon as its waiting time expires. For example, suppose a normal node receives beacon packet from two different beacon nodes \(B_{1}\) and \(B_{2}\). As shown in Figure 3(a), from the sensing range of \(B_{1}\), the line joining the normal and anchor node can have two possible coordinates \(P_{1}\) and \(P_{1}^{\prime}\). Similarly, from the sensing range of \(B_{2}\), another two possible coordinates \(P_{2}\) and \(P_{2}^{\prime}\) can be obtained. Then, the normal node compares the distance between each combination of points, _i.e._, \(P_{1}\) with \(P_{2}\) or \(P_{2}^{\prime}\) with \(P_{1}^{\prime}\) or any other pairs. Finally, it chooses the pair of points having minimum distance or very negligible distance. \begin{table}
\begin{tabular}{|c|c|c|c|} \hline BN-ID & BN-loc. & RSSI & P-loc \\ \hline \(B_{1}\) & (\(X_{B1}\),\(Y_{B_{1}}\)) & \(RSSI_{B_{1}}\) & \(P_{1}\) \\ \hline \(B_{2}\) & (\(X_{B2}\),\(Y_{B_{2}}\)) & \(RSSI_{B_{2}}\) & \(P_{2}^{\prime}\) \\ \hline \(B_{3}\) & (\(X_{B3}\),\(Y_{B_{3}}\)) & \(RSSI_{B_{3}}\) & \(P_{3}^{\prime}\) \\ \hline \(B_{4}\) & (\(X_{B4}\),\(Y_{B_{4}}\)) & \(RSSI_{B_{4}}\) & \(P_{4}\) \\ \hline... &... &... &... \\ \hline \end{tabular}
\end{table} 
Table 1: Coordinate table. As shown in Figure 3(a), obviously points \(P_{1}^{\prime}\) and \(P_{2}^{\prime}\) are selected as the most possible location of the nodes. As shown in Figure 3(b), if more than two beacon packets are received from three different beacon nodes, normal node continues to update the coordinate table and use the same procedure to compute the possible coordinates \(P_{3}\) and \(P_{3}^{\prime}\) and determines the correct coordinate. If more than three beacon packets are received from different beacon nodes after the waiting time is elapsed, a normal node selects three of all entity in the table having smallest RSSI value, as the error measurement of distance increases if the RSSI value is increased. By choosing the smallest RSSI value, the percentage of localization error can be minimized. In case, one beacon packet is received by the normal node during its waiting time, it implies that there is only one entity in the table with two possible coordinates \(P_{1}\) and \(P_{1}^{\prime}\). In this case, a normal node randomly chooses one of the two possible coordinates as its estimated location.