## 2 Modeling of Magnetic Field
### Mathematical Model of a Single Rectangular Coil  
The mathematical model of the rectangular coil is established to provide a theoretical basis for the magnetic field control, to establish the actuation matrix and realize the actuation algorithm. According to the Biot-Savart law, the magnetic induction generated at a point \(P(x,y,z)\) by a current element \(Idl\) can be calculated as follows:  
\[dB=\frac{\mu_{0}}{4\pi}\frac{Idl\times(r-r^{\prime})}{|r-r^{\prime}|^{3}} \tag{3}\]  
where \(r^{\prime}\) is the coordinate vector of the current element; \(r\) is the coordinate vector of the space field position \(P\); \(dl\) is the length of the microcurrent element, and its current magnitude is \(I\); \(\mu_{0}\) is the vacuum permeability and equals to \(4\pi\times 10^{-7}N/A^{2}\). In the case of an online current, the integral path is \(L^{\prime}\), whereby the magnetic induction generated by the field source at any point in space can be calculated by the following equation  
\[B(r)=\frac{\mu_{0}I}{4\pi}\int_{L^{\prime}}\frac{dl\times(r-r^{\prime})}{|r-r^ {\prime}|^{3}} \tag{4}\]  
As shown in Figure 3, the length, width, and height of this rectangular coil are \(2l\), \(2w\), and \(2h\), respectively. The direction of the current is shown in the figure using arrows. By using the center of this electromagnetic coil as the origin point, the coordinate is built. Based on the Biot-Savart Law, it isdetermined that the magnetic field generated by the surface current of the rectangular coil at point \(P=(a,b,c)^{T}\) is the linear superposition of the magnetic fields generated by the currents of the respective segments of 1, 2, 3, and 4. In the \(X\) axial direction, the rectangular current loop is uniformly distributed in a single layer, whereby the magnetic component of the entire rectangular electromagnetic coil at one point can be expressed as:  
\[\textbf{B}=\left(\int_{-l}^{l}\sum_{i=1}^{4}dB_{xi},\int_{-l}^{l}\sum_{i=1}^{4 }dB_{yi},\int_{-l}^{l}\sum_{i=1}^{4}dB_{zi}\right) \tag{5}\]  
In our prior work, the analytical expression of the magnetic field component produced by a single rectangular electromagnetic coil at a point in space can be written as [22]:  
\[ \begin{split} B_{x}=& K(f_{1}(a,c-h,b-w)-f_{1}(a,c- h,b+w)\\ &+f_{1}(a,b+w,c+h)-f_{1}(a,b+w,c-h)\\ &+f_{1}(a,c+h,b+w)-f_{1}(a,c+h,b-w)\\ &+f_{1}(a,b-w,c-h)-f_{1}(a,b-w,c+h))\end{split}  \tag{6}\]  
\[ \begin{split} B_{y}=& K(f_{2}(a,b+w,c-h)-f_{2}(a,b+w,c+h)\\ &+f_{2}(a,b-w,c+h)-f_{2}(a,b-w,c-h))\end{split}  \tag{7}\]  
\[ \begin{split} B_{z}=& K(f_{2}(a,c-h,b+w)-f_{2}(a,c- h,b-w)\\ &+f_{2}(a,c+h,b-w)-f_{2}(a,c+h,b+w))\end{split}  \tag{8}\]  
Figure 3: Modeling of the rectangular coil. The coordinate system is based on the coil. The \(X\)-axis is along the length of the coil and the origin of the coordinate is at the center position of the coil. The model is based on the Biot–Savart Law and the superposition principle. The direction of the current \(I\) is different in the four different planes. where  
\[ \begin{split} f_{1}(a,b,c)=&-atan\left(\frac{c(a-l)}{b \sqrt{(a-l)^{2}+b^{2}+c^{2}}}\right)\\ &+atan\left(\frac{c(a+l)}{b\sqrt{(a+l)^{2}+b^{2}+c^{2}}}\right)\\ f_{2}(a,b,c)=&-atanh\left(\frac{\sqrt{(a-l)^{2}+b^{2} +c^{2}}}{c}\right)\\ &+atanh\left(\frac{\sqrt{(a+l)^{2}+b^{2}+c^{2}}}{c}\right)\end{split}  \tag{9}\]  
For each given position \((a,b,c)^{T}\) that outside the coils, \(B_{r}\) can be estimated based on the above equations. Therefore, torque can be calculated with (1). Define \(\Psi_{1}\) and \(\Psi_{2}\) as follows:  
\[\Psi_{1}= atan(\frac{zx}{y\sqrt{x^{2}+y^{2}+z^{2}}}) \tag{11}\] \[\Psi_{2}= atanh(\frac{\sqrt{x^{2}+y^{2}+z^{2}}}{z}) \tag{12}\]  
Then,  
\[\left[ \begin{array}{c}\frac{\partial\Psi_{1}}{\partial x}\\ \frac{\partial\Psi_{1}}{\partial y}\\ \frac{\partial\Psi_{1}}{\partial z}\end{array} \right]\;=\;\left[ \begin{array}[ ]{c}\frac{yz}{(x^{2}+y^{2})\sqrt{x^{2}+y^{2}+z^{2}}}\\ -\frac{xz(x^{2}+2y^{2}+z^{2})}{(x^{2}+y^{2})(y^{2}+z^{2})\sqrt{x^{2}+y^{2}+z^{ 2}}}\\ \frac{xy}{(y^{2}+z^{2})\sqrt{x^{2}+y^{2}+z^{2}}}\end{array}