# Synthesis of Four-Link Initial Kinematic Chains with Spherical Pairs for Spatial Mechanisms
## 2 Materials and Methods
\begin{bmatrix}e_{i1}^{2}e_{i1}^{1}+m_{ i1}^{2}m_{i1}^{1}+n_{i1}^{2}n_{i1}^{1}&e_{i1}^{2}e_{i2}^{1}+m_{i1}^{2}m_{i2}^{1}+n_{i1}^{2 }n_{i2}^{1}&e_{i1}^{2}e_{i3}^{1}+m_{i1}^{2}m_{i3}^{1}+n_{i1}^{2}n_{i3}^{1}&0\\ e_{i2}^{2}e_{i1}^{1}+m_{i2}^{2}m_{i1}^{1}+n_{i2}^{2}n_{i1}^{1}&m_{i2}^{2}e_{i1}^ {2}+m_{i2}^{2}m_{i2}^{1}+m_{i2}^{2}n_{i1}^{1}&m_{i2}^{2}e_{i3}^{1}+m_{i2}^{2} m_{i3}^{1}+m_{i2}^{2}n_{i3}^{1}&0\\ n_{i3}^{2}e_{i1}^{1}+n_{i3}^{2}n_{i1}^{1}+n_{i3}^{2}n_{i1}^{1}&n_{i3}^{2}e_{i2}^ {1}+n_{i3}^{2}m_{i2}^{1}+n_{i3}^{2}n_{i2}^{1}&n_{i3}^{2}e_{i3}^{1}+n_{i3}^{2} m_{i3}^{1}+n_{i3}^{2}n_{i3}^{1}&0\\ 0&0&0&1\end{bmatrix} \\ 0&0&0&1\end{bmatrix}\\ (12)  
This represents a similar transformation for point \(C\), which involves both a translation and rotation between the frames of \(Q_{1}\) and \(Q_{2}\). Each of these matrices is a combination of rotation matrices (representing the orientation of the rigid bodies \(Q_{1}\) and \(Q_{2}\) relative to the global coordinate frame) and translation matrices (replacing the initial position of the rigid bodies). The purpose of these transformations is to calculate the relative positions of points \(A\), \(B\), and \(C\) on the rigid bodies \(Q_{1}\) and \(Q_{2}\) based on the coordinate transformations [17]. These transformations take into account both the orientation and position of the rigid bodies in space, using Euler angles for rotations and coordinates for translations. This is a function of ten parameters: \(X_{A}\), \(Y_{A}\), \(Z_{A}\), \(x_{B}\), \(y_{B}\), \(z_{B}\), \(x_{C}\), \(y_{C}\), \(z_{C}\). Grouping these parameters into fours with a common parameter \(R\), we present the weighted difference in three different forms. Weighted difference for point \(A\):  
\[\Delta q_{i}^{(1)}=(X_{Ai}-X_{A})^{2}+(Y_{Ai}-Y_{A})^{2}+(Z_{Ai}-Z_{A})^{2}-R^{2} \tag{13}\]  
Weighted difference for point \(B\):  
\[\Delta q_{i}^{(2)}=(X_{Bi}-X_{B})^{2}+(Y_{Bi}-Y_{B})^{2}+(Z_{Bi}-Z_{B})^{2}-R^{2} \tag{14}\]  
Weighted difference for point \(C\):  
\[\Delta q_{i}^{(3)}=(X_{Ci}-X_{C})^{2}+(Y_{Ci}-Y_{C})^{2}+(Z_{Ci}-Z_{C})^{2}-R^{2} \tag{15}\]The total objective function to minimize, which is the sum of the squared differences, can be written as  
\[S=\sum_{i=1}^{N}\biggl{[}\left(\Delta q_{i}^{(1)}\right)^{2}+\left(\Delta q_{i}^ {(2)}\right)^{2}+\left(\Delta q_{i}^{(3)}\right)^{2}\biggr{]} \tag{16}\]  
The sum here is taken over all \(N\) discrete positions of the solids. Since each \(\Delta q_{i}^{(k)}\) (for \(k=1\), \(2\), \(3\)) is expressed in terms of \(X_{A}\), \(Y_{A}\), \(Z_{A}\), \(x_{B}\), \(y_{B}\), \(z_{B}\), \(x_{C}\), \(y_{C}\), \(z_{C}\), and \(R\), the objective function \(S\) is a function of these ten parameters. We represent the weighted differences as groups of parameters with a common parameter \(R\) into four sets. For each of the three members, the variables \(X_{A}\), \(Y_{A}\), \(Z_{A}\) (for point \(A\)); \(x_{B}\), \(y_{B}\), \(z_{B}\) (for point \(B\)); and \(x_{C}\), \(y_{C}\), \(z_{C}\) (for point \(C\)) are grouped together, and their corresponding coordinates \(X_{A}\), \(Y_{A}\), \(Z_{A}\), \(x_{B}\), \(y_{B}\), \(z_{B}\), and \(x_{C}\), \(y_{C}\), \(z_{C}\) are scaled relative to the common radius \(R\). To find the optimal positions and radius that minimize \(S\), we need to compute the partial derivatives of \(S\) with respect to each parameter (i.e., the positions and \(R\)), and set these derivatives equal to zero. The total objective function is  
\[ \begin{array}{c}S=\sum_{i=1}^{N}[\left((X_{Ai}-X_{A})^{2}+(Y_{Ai}-Y_{A})^{2}+ (Z_{Ai}-Z_{A})^{2}-R^{2}\right)^{2}+\left((X_{Bi}-X_{B})^{2}+(Y_{Bi}-Y_{B})^{2 }+(Z_{Bi}-Z_{B})^{2}-R^{2}\right)^{2}\\ \hskip 113.811024 pt+\left((X_{Ci}-X_{C})^{2}+(Y_{Ci}-Y_{C})^{2}+(Z_{Ci}-Z_{C}) ^{2}-R^{2}\right)^{2}\end{array}  \tag{17}\]  
Now, to minimize \(S\), we calculate the partial derivatives of \(S\) with respect to each of the ten parameters \(X_{A}\), \(Y_{A}\), \(Z_{A}\), \(x_{B}\), \(y_{B}\), \(z_{B}\), \(x_{C}\), \(y_{C}\), \(z_{C}\), and \(R\), and set them equal to zero:  
\[