# A Novel Method for Risk Assessment and Simulation of Collision Avoidance for Vessels based on AIS
## 4 Collision Avoidance Algorithm  
In the collision avoidance algorithm, it is important to determine the movement parameters of the ship compared to the target vessel, which is the basis of the calculation type and case judgment [11]. The following is a series of ship motion calculations based on the Descartes coordinate system:  
The speeds of the master and target ships on the axle component is [32]:  
\[\left\{ \begin{array}{l}v_{x_{0}}=v_{0}\sin\varphi_{0}\\ v_{y_{0}}=v_{0}\cos\varphi_{0}\end{array} \right.\left\{ \begin{array}{l}v_{x_ {\mathrm{T}}}=v_{\mathrm{T}}\sin\varphi_{\mathrm{T}}\\ v_{y_{\mathrm{T}}}=v_{\mathrm{T}}\cos\varphi_{\mathrm{T}}\end{array} \right., \tag{4}\]  
where \((x_{0},\,y_{0})\) are the geographic coordinates of the ship with the velocity of \(v_{0}\), and the direction of \(\varphi_{0}\). \((x_{\mathrm{T}},y_{\mathrm{T}})\) are the coordinates of the target vessel with a velocity of \(v_{\mathrm{T}}\), and a direction of \(\varphi_{\mathrm{T}}\). The relative velocities of the two ships on the \(x\) and \(y\) axes are given by [32]:  
\[\left\{ \begin{array}{l}v_{x_{\mathrm{R}}}=v_{x_{\mathrm{T}}}-v_{x_{0}}\\ v_{y_{\mathrm{R}}}=v_{y_{\mathrm{T}}}-v_{y_{0}}\end{array} \right. \tag{5}\]  
The magnitude of the relative speed is [32]:  
\[v_{\mathrm{R}}=\sqrt{{v_{x_{\mathrm{R}}}}^{2}+{v_{y_{\mathrm{R}}}}^{2}} \tag{6}\]  
The relative direction is [32]:  
\[\varphi_{\mathrm{R}}=\arctan\frac{v_{x_{\mathrm{R}}}}{v_{y_{\mathrm{R}}}}+\alpha, \tag{7}\]  
where:  
\[\alpha=\left\{ \begin{array}{l}0\quad v_{x_{\mathrm{R}}}\geq 0,\,\,\,v_{y_{ \mathrm{R}}}\geq 0\\ \pi\quad v_{x_{\mathrm{R}}}<0,\,\,v_{y_{\mathrm{R}}}<0\\ \pi\quad v_{x_{\mathrm{R}}}\geq 0,\,\,v_{y_{\mathrm{R}}}<0\\ 2\pi\quad v_{x_{\mathrm{R}}}<0,\,\,v_{y_{\mathrm{R}}}\geq 0\end{array} \right. \tag{8}\]  
The relative distance between the two ships is [32]:  
\[R=\sqrt{{(x_{\mathrm{T}}-x_{0})}^{2}+{(y_{\mathrm{T}}-y_{0})}^{2}} \tag{9}\]  
The bearing direction of the master ship with the target vessel is [32]:  
\[\alpha_{0}=\arctan\frac{x_{0}-x_{\mathrm{T}}}{y_{0}-y_{\mathrm{T}}}+\alpha \tag{10}\]  
The DCPA between the two ships is [12; 32]:  
\[DCPA=\left|R\sin(\varphi_{\mathrm{R}}-\alpha_{\mathrm{T}}-\pi)\right| \tag{11}\]  
The TCPA between the two ships is [12; 32]:  
\[TCPA=\left|\frac{R\cos(\varphi_{\mathrm{R}}-\alpha_{\mathrm{T}}-\pi)}{v_{ \mathrm{R}}}\right| \tag{12}\]  
The azimuth between the ship and the target ship can be expressed as [12; 32]:  
\[\Delta B=B_{t}-B_{o}, \tag{13}\]where \(B_{o}=C_{o}\). The speed factor is given by [12; 32]:  
\[K=\frac{V_{o}}{V_{t}} \tag{14}\]  
When the TCPA is less than or equal to zero, it means that the two vessels have passed the closest approach, which is defined as the presence of a collision. \(DCPA\), \(TCPA\), \(R\), \(\Delta B\) and \(K\), are components of the mathematical model of collision risk assessment. \(R\) and \(DCPA\) represent the collision space, \(TCPA\) represents the collision time, and \(K\) represents the difficulty of the collision avoidance. The values of \(\Delta B\) and \(K\) affect the avoidance behavior when they are considered to be at a high or low risk of collision. These parameters in the mathematical model and the simulation program of crash risk are called functional functions [33]. The functional function of DCPA is [33]:  
\[U_{DCPA}=\left\{ \begin{array}{ll}1&DCPA\leq d_{1}\\ \frac{1}{2}-\frac{1}{2}\sin[\frac{\pi}{d_{2}-d_{1}}(DCPA-\frac{d_{1}+d_{2}}{ 2})]&d_{1}<DCPA\leq d_{2}\\ 0&d_{2}<DCPA\end{array} \right. \tag{15}\]  
where \(d_{1}\) is the minimum safe pass distance, and \(d_{2}\) is the safe encounter distance. \(d_{1}\) and \(d_{2}\) can be expressed as [33]:  
\[ \begin{array}{ll}d_{1}=SDA\times N\\ d_{2}=K\times d_{1}\end{array}  \tag{16}\]  
where the ship safe distance of approach (SDA) is the fuzzy distance when the sailor operates. N is the relative value representing the instantaneous visibility, for the AIS system, N = 1.