# Optimization Method of Square Hole Measurement Based on Generalized Point Photogrammetry
## 4 Mathematical Model of Square Hole Measurement Based on Constraint Conditions  
As shown in Figure 4, it is a schematic diagram of a space square hole. Under ideal conditions, the four points \(A\), \(B\), \(C\) and \(D\) are in the same plane and form a plane square. The spatial coordinates of the four points are \((X_{1},Y_{1},Z_{1})\), \((X_{2},Y_{2},Z_{2})\), \((X_{3},Y_{3},Z_{3})\) and \((X_{4},Y_{4},Z_{4})\). Line segment \(L_{1}\) is determined by point \(A\) and \(B\), line segment \(L_{2}\) is determined by point \(B\) and \(C\), line segment \(L_{3}\) is determined by point \(C\) and \(D\), and line segment \(L_{4}\) is determined by point \(A\) and \(D\). \(S_{1}\) and \(S_{2}\) are the projection centers of the two images. Points \(a_{1}\), \(b_{1}\), \(c_{1}\) and \(d_{1}\) are the projection of the spatial points \(A\), \(B\), \(C\) and \(D\) on the first image. Points \(a_{2}\), \(b_{2}\), \(c_{2}\) and \(d_{2}\) are the projection of the spatial points on the second image.  
Since the four points form a plane square, the following constraints need to be set.  
\[\begin{array}{l}\overrightarrow{L_{1}}\bot\overrightarrow{L_{2}}\\ \overrightarrow{L_{1}}\bot\overrightarrow{L_{4}}\\ \overrightarrow{L_{2}}\bot\overrightarrow{L_{3}}\\ \overrightarrow{L_{3}}\bot\overrightarrow{L_{4}}\\ \overrightarrow{|L_{1}|}\bot\overrightarrow{|L_{2}|}=m\end{array} \tag{28}\]  
where, \(m\) is the square side length.  
The following formula can be obtained from the constraint conditions.  
\[\begin{array}{l}(X_{2}-X_{1},Y_{2}-Y_{1},Z_{2}-Z_{1})(X_{3}-X_{2},Y_{3}-Y_{ 2},Z_{3}-Z_{2})=0\\ (X_{2}-X_{1},Y_{2}-Y_{1},Z_{2}-Z_{1})(X_{4}-X_{1},Y_{4}-Y_{1},Z_{4}-Z_{1})=0\\ (X_{3}-X_{4},Y_{3}-Y_{4},Z_{3}-Z_{4})(X_{3}-X_{2},Y_{3}-Y_{2},Z_{3}-Z_{2})=0\\ (X_{3}-X_{4},Y_{3}-Y_{4},Z_{3}-Z_{4})(X_{4}-X_{1},Y_{4}-Y_{1},Z_{4}-Z_{1})=0\\ (X_{2}-X_{1})^{2}+(Y_{2}-Y_{1})^{2}+(Z_{2}-Z_{1})^{2}-m^{2}=0\\ (X_{2}-X_{3})^{2}+(Y_{2}-Y_{3})^{2}+(Z_{2}-Z_{3})^{2}-m^{2}=0\end{array} \tag{29}\]For the first constraint, the following equation can be obtained after the formula is functioned.  
\[\begin{array}{l}F_{1}^{\rm K}=F_{1}^{0}+\frac{\partial F_{1}}{\chi_{1}}dX_{1}X_{ 1}+\frac{\partial F_{1}}{\chi_{2}}dX_{2}+\frac{\partial F_{1}}{\chi_{3}}dX_{3} +\frac{\partial F_{1}}{\chi_{4}}dX_{4}\\ +\frac{\partial F_{1}}{\chi_{1}}dY_{1}+\frac{\partial F_{1}}{\chi_{2}}dY_{2}+ \frac{\partial F_{1}}{\chi_{3}}dY_{3}+\frac{\partial F_{1}}{\chi_{4}}dY_{4}\\ +\frac{\partial F_{1}}{\chi_{1}}dZ_{1}+\frac{\partial F_{1}}{Z_{2}}dZ_{2}+ \frac{\partial F_{1}}{Z_{3}}dZ_{3}+\frac{\partial F_{1}}{Z_{4}}dZ_{4}\end{array} \tag{30}\]  
where,  
\[\begin{array}{l}\frac{\partial F_{1}}{\partial X_{1}}=X_{2}-X_{3},\frac{ \partial F_{1}}{\partial X_{2}}=-2X_{2}+X_{3}+X_{1},\frac{\partial F_{1}}{ \partial X_{3}}=X_{2}-X_{1},\frac{\partial F_{1}}{\partial X_{4}}=0\\ \frac{\partial F_{1}}{\partial Y_{1}}=Y_{2}-Y_{3},\frac{\partial F_{1}}{ \partial Y_{2}}=-2Y_{2}+Y_{3}+Y_{1},\frac{\partial F_{1}}{\partial Y_{3}}=Y_{2 }-Y_{1},\frac{\partial F_{1}}{\partial Y_{1}}=0\\ \frac{\partial F_{1}}{\partial Z_{1}}=Z_{2}-Z_{3},\frac{\partial F_{1}}{ \partial Z_{2}}=-2Z_{2}+Z_{3}+Z_{1},\frac{\partial F_{1}}{\partial Z_{3}}=Z_{2 }-Z_{1},\frac{\partial F_{1}}{\partial Z_{4}}=0\end{array} \tag{31}\]  
In the same way, linearization formulas for other constraints can be obtained. After the error equations of all observation points are established, iterative calculation can be carried out to obtain the precise spatial coordinates of the four points of the square hole.