# Detection of Intelligent Intruders in Wireless Sensor Networks
## 3 Intrusion Algorithms
### Pinball Intrusion Algorithm  
Motivated by the kinetic theory behind billiards or pinball balls rebounding off a collision with equal kinetic energy [26; 27], we propose the pinball algorithm for detection avoidance. Intruders following this detection avoidance strategy, called pinball intruders, will bounce away with a constant speed after encountering the boundaries of WSN FoI or detecting the sensing coverage area of a sensor within its sensing range \(I_{rs}\). To be specific, the intruder starts its intrusion from the left periphery of the WSN FoI and moves toward the right periphery, aiming to safely pass the WSN and reach its destination in a timely manner. During its traversal, the intruder might sense a nearby sensor (within distance \(I_{rs}\)) or an edge of the FoI. If the intruder senses the left, upper, or bottom edge of the FoI, it will invert the \(x\) or \(y\) component of its velocity as if a ball hits the vertical or horizontal edges, respectively. On the other hand, if the intruder senses the sensing coverage area of a sensor that is modeled as a circular disk with radius \(r_{s}\), the normal of the reflection surface becomes the line between the intruder and the sensor. As illustrated in Figure 2, let \(\vec{I}\) and \(\vec{S}\) be the position vectors of the intruder and sensor detected. The \(x\) and \(y\) components of any vector \(\vec{A}\) are denoted as \(A_{x}\) and \(A_{y}\), respectively. The normal of the reflection surface is thus the mirror vector \(\vec{M}=\vec{I}-\vec{S}\). Assume the intruder's initial velocity is \(\vec{v}_{i}\), and the resulting velocity is \(\vec{v}_{f}\) after bouncing off the sensor for collision avoidance. Using some vector math, \(\vec{v}_{f}\) can be computed by calculating the angle \(\theta\) and performing a rotation on \(\vec{v}_{i}\), as shown below. \[\theta=\text{atan2}(M_{y},M_{x})-\text{atan2}(-v_{iy},-v_{iy}) \tag{1}\]  
\[\text{atan2}(y,x)=\left\{ \begin{array}{ll}\arctan\frac{y}{y};&(x>0)\\ \arctan\frac{y}{x}+\pi;&(y\geq 0,x<0)\\ \arctan\frac{y}{x}-\pi;&(y<0,x<0)\\ \frac{\pi}{2};&(y>0,x=0)\\ -\frac{\pi}{2};&(y<0,x=0)\\ \text{undefined},&(y=0,x=0)\end{array} \right. \tag{2}\] \begin{table}
\begin{tabular}{c c} \hline \hline
**Notation** & **Description** \\ \hline \(L\) & Side length of the field of interest \\ \(N\) & Number of sensors deployed \\ \(r_{s}\) & Sensing range \\ \(r_{c}\) & Communication range \\ \(I_{rs}\) & Intruder sensing range \\ \(\lambda\) & Node density \\ \(P_{det}\) & Detection probability \\ \(P_{prevt}\) & Prevention probability \\ \(P_{usn}\) & WSN win probability \\ \(P_{intru}\) & Intruder escape probability \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Notation table. After solving for \(\theta\), twice that value is the angle that \(-\vec{v}_{i}\) is to be rotated. Rotating \(-\vec{v}_{i}\) by \(2\theta\) gives the resultant velocity \(\vec{v_{f}}\). \[v_{fx} = (-v_{ix})cos(2\theta)-(-v_{iy})sin(2\theta); \tag{3}\] \[= -v_{ix}cos(2\theta)+v_{iy}sin(2\theta)\]  
\[v_{fy} = (-v_{ix})sin(2\theta)+(-v_{iy})cos(2\theta); \tag{4}\] \[= -v_{ix}sin(2\theta)-v_{ix}cos(2\theta)\]  
\[\vec{v_{f}}=v_{fx}\hat{x}+v_{fy}\hat{y} \tag{5}\]  
By setting the velocity to \(\vec{v_{f}}\) upon the intruder's detection of any sensor or wall, the intruder avoids sensors by reflecting off of potential detection points. The pseudocode of the pinball intrusion algorithm is also described in Algorithm 1. Note that some functionality is simplified into several functions to improve readability in Algorithm 1. To be specific:  
* \(normalize(\vec{v})\) performs vector normalization. It returns a vector that points in the same direction as the input vector, but with a length of one. * \(collides(\vec{p},obj)\) performs sensor/wall detection between the entity's original position and the next position \(\vec{p}\) against the detected \(obj\) (_i.e._, a sensor or an FoI boundary). In the case of an FoI boundary, the function will check for the intersection of two line segments.