# Research on Intelligent Optimization of Wellbore Trajectory in Complex Formation
## 3 Borehole Trajectory Optimization Model
When \((\varphi-\varphi_{0})-(\alpha-\alpha_{0})\
eq 0\):  
\[ \begin{array}{c}\Delta Z=\frac{\Delta L(\sin\alpha-\sin a_{0})}{a-\alpha_{0}} \\ \Delta N=\frac{\Delta L[\cos(\varphi-a)-\cos(\varphi_{0}-a_{0})]}{2[(\varphi- \varphi_{0})-(\alpha-\alpha_{0})]}-\frac{\Delta L[\cos(\varphi+a)-\cos(\varphi_ {0}+a_{0})]}{2[(\varphi-\varphi_{0})-(\alpha-\alpha_{0})]}\\ \Delta E=\frac{\Delta L[\sin(\varphi-a)-\sin(\varphi_{0}-a_{0})]}{2[(\varphi- \varphi_{0})-(\alpha-\alpha_{0})]}-\frac{\Delta L[\sin(\varphi+a)-\sin(\varphi _{0}+a_{0})]}{2[(\varphi-\varphi_{0})+(\alpha-\alpha_{0})]}\end{array}  \tag{5}\]  
When \((\varphi-\varphi_{0})-(\alpha-\alpha_{0})=0\):  
\[ \begin{array}{c}\Delta Z=\frac{\Delta L(\sin\alpha-\sin a_{0})}{a-\alpha_{0} }\\ \Delta N=\frac{\Delta L[\cos(\varphi+a)-\cos(\varphi_{0}+a_{0})]}{2[(\varphi- \varphi_{0})+(\alpha-\alpha_{0})]}-\frac{\Delta L\sin(\varphi_{0}-a_{0})}{2} \\ \Delta E=\frac{\Delta L[\sin(\varphi+a)-\sin(\varphi_{0}+a_{0})]}{2[(\varphi- \varphi_{0})+(\alpha-\alpha_{0})]}-\frac{\Delta L\cos(\varphi_{0}-a_{0})}{2} \end{array}  \tag{6}\]  
In order to establish a nonlinear constraint equation that can be used to solve the optimization theory, the coordinate increment calculation formula is transformed. Suppose that the unknown variable \(x_{1},\ x_{2},\ x_{3}\) corresponds to the well depth increment \(\Delta L\), the well deviation angle \(\alpha\), and the azimuthal angle \(\varphi\), respectively. Then, the formula can be transformed into:  
\[F(x)= \begin{cases}f_{1}\\ f_{2}\\ f_{3}\end{cases} = \begin{cases}\frac{x_{1}[\sin x_{2}-\sin a_{0}]}{x_{2}-\alpha _{0}}-\Delta Z=0\\ \frac{x_{1}[\cos(x_{2}-x_{2})-\cos(\varphi_{0}-a_{0})]}{2[(x_{3}-\varphi_{0}) -(x_{2}-a_{0})]}-\frac{x_{1}[\cos(x_{2}+x_{2})-\cos(\varphi_{0}+a_{0})]}{2[(x_ {3}-\varphi_{0})+(x_{2}-a_{0})]}-\Delta N=0\\ \frac{x_{1}[\sin(x_{3}-x_{2})-\sin(\varphi_{0}-a_{0})]}{2[(x_{3}-\varphi_{0}) -(x_{2}-a_{0})]}-\frac{x_{1}[\sin(x_{3}+x_{2})-\sin(\varphi_{0}+a_{0})]}{2[(x_ {3}-\varphi_{0})+(x_{2}-a_{0})]}-\Delta E=0\end{cases}  \tag{7}\]  
Solving the above, \(F(x)=0\) can be further transformed into a nonlinear constraint equation solving problem with the minimum sum of squares of the increment difference of wellbore trajectory coordinates as the objective function and the increment of well depth, deviation angle, and azimuth range as constraints. The details are as follows:  
\[F_{1}=\left(\Delta N_{ab}+\Delta N_{bc}-N_{c}\right)^{2}+\left(\Delta E_{ab}+ \Delta E_{bc}-E_{c}\right)^{2}+\left(D_{kbp}+\Delta D_{ab}+\Delta D_{bc}-D_{c} \right)^{2} \tag{8}\]  
Of which:  
\[ \begin{array}{c}L_{ab}=R_{i}*\alpha_{i}\\ L_{bc}=\frac{D_{c}-D_{kbp}-R_{i}*\sin a_{i}}{\cos a_{i}}\\ \Delta E_{ab}=R_{i}(1-\cos\alpha_{i})\sin\varphi_{i}\\ \Delta N_{ab}=R_{i}(1-\cos\alpha_{i})\cos\varphi_{i}\\ \Delta D_{ab}=R_{i}\sin\alpha_{i}\\ \Delta N_{bc}=L_{bc}\sin\alpha_{i}\cos\varphi_{i}\\ \Delta E_{bc}=L_{bc}\sin\alpha_{i}\sin\varphi_{i}\\ \Delta D_{bc}=L_{bc}\cos\alpha_{i}\end{array}  \tag{9}\]  
Considering the complexity of the orbit, the objective function is as follows:  
\[Q(\alpha,\phi_{i},R_{i})=\sum_{i=1}^{s}si(\frac{180\times 30}{\pi R_{i}})^{2} \tag{10}\]  
Of which:  
\[ \begin{array}{c}s_{i}=R_{i}\theta_{i}\\ \theta_{i}=\arccos\alpha_{i-1}\cos\alpha_{i}+\sin\alpha_{i-1}\sin\alpha_{i}\cos( \varphi_{i}-\varphi_{i-1})\end{array}  \tag{11}\]