## 3 Methodology
#### 3.1.1 Model Derivation
The elevation angle (\(\theta_{y}\)) and azimuth angle (\(\theta_{x}\)) of point \(M\) correspond to its position coordinates (\(X_{d},\ Z_{d},\ Y_{d}\)). Equation (5) can be obtained from the geometric relationship in Figure 2, as follows:  
\[\left\{ \begin{aligned} X_{d}&=P\tan\theta_{x}\\ Z_{d}&=P\\ Y_{d}&=P\frac{tan\theta_{x}}{cos\theta_{x}}\end{aligned}  \right., \tag{5}\]  
The ship's posture variation is shown in Figure 3. The positive Z-axis aligns with the ship's bow direction; the Y-axis is perpendicular to the ship's deck; and the X-axis is orthogonal to the ship's side. Let the yaw angle be \(\alpha\), the pitch angle be \(\beta\), and the roll angle be \(\gamma\); these represent the disturbances in the transformation from the local coordinate system of the ship to the geodetic rectangular coordinate system. When the three degrees of freedom of the ship's  
Figure 3: Mode of ship attitude change with three degrees of freedom. Figure 2: Point \(M\) on the scan path is located in the geodetic coordinate system. posture occur simultaneously, the target position in the deck coordinate system (\(X,\ Z,\ Y\)) can be obtained by multiplying the ship's posture-transformation matrix, as follows:  
\[ \begin{bmatrix}X\\ Z\\ Y\end{bmatrix} =G_{\gamma}G_{\beta}G_{\alpha} \begin{bmatrix}X_{d}\\ Z_{d}\\ Y_{d}\end{bmatrix} = \begin{bmatrix}\cos\gamma&0&\sin\gamma\\ 0&1&0\\ -\sin\gamma&0&\cos\gamma\end{bmatrix}\begin{bmatrix}1&0&0\\ 0&\cos\beta&-\sin\beta\\ 0&\sin\beta&\cos\beta\end{bmatrix}\begin{bmatrix}\cos\alpha&-\sin\alpha&0\\ \sin\alpha&\cos\alpha&0\\ 0&0&1\end{bmatrix}\begin{bmatrix}X_{d}\\ Z_{d}\\ Y_{d}\end{bmatrix} , \tag{6}\]  
Since the roll motion is a rotation around the Z-axis, which coincides with the optical axis, and the observation plane is perpendicular to the Z-axis, the final Cartesian coordinates (\(X,\ Y\)) of the compensated dual-grating observation plane are obtained as follows:  
\[X =(\cos\alpha\cos\gamma+\sin\alpha\sin\beta\sin\gamma)X_{d}+(-\sin \alpha\cos\gamma+\cos\alpha\sin\beta\sin\gamma)Z_{d}+(\cos\beta\sin\gamma)Y_{d} \tag{7}\] \[Y =(-\cos\alpha\sin\gamma+\sin\alpha\sin\beta\cos\gamma)X_{d}+(\sin \alpha\sin\gamma+\cos\alpha\sin\beta\cos\gamma)Z_{d}+(\cos\beta\cos\gamma)Y_{d} \tag{8}\]  
By substituting the compensated Cartesian coordinates of the dual-grating two-dimensional scanning pattern (7) and (8) into (1)-(5), the rotating dual-grating two-dimensional scanning model (9) and (10) can be established. At this point, the rotating dual-grating two-dimensional scanning model can not only correct the errors caused by the ship's disturbance but also control the trajectory of the grating's emitted beam to make it a straight line, thus enabling stable scanning of the beam in the two-dimensional plane. \[ \begin{cases}\theta_{1}=\tan^{-1}\frac{Y}{X}-\sin^{-1}\begin{bmatrix}\frac{\Lambda \sin\left(\tan^{-1}\frac{\sqrt{X_{d}^{2}+Y^{2}}}{p}\right)}{2\lambda}\\ \theta_{2}=\tan^{-1}\frac{Y}{X}+\sin^{-1}\begin{bmatrix}\frac{\Lambda\sin\left( \tan^{-1}\frac{\sqrt{X_{d}^{2}+Y^{2}}}{p}\right)}{2\lambda}\end{bmatrix}\end{cases}  \tag{9}\]  
\[ \begin{cases}\theta_{1}=\tan^{-1}\frac{Y}{X}-\sin^{-1}\begin{bmatrix}\frac{ \Lambda\sin\left(\tan^{-1}\frac{\sqrt{X_{d}^{2}+Y^{2}}}{p}\right)}{2\lambda} \end{bmatrix}+\pi\\ \theta_{2}=\tan^{-1}\frac{Y}{X}+\sin^{-1}\begin{bmatrix}\frac{\Lambda\sin\left( \tan^{-1}\frac{\sqrt{X_{d}^{2}+Y^{2}}}{p}\right)}{2\lambda}\end{bmatrix}+\pi \end{cases}  \tag{10}\]