## 5 Shape Fitting
### Inside-Outside Function  
Superquadrics are a set of geometric shapes. In a basic superquadric, the center is assumed to be the origin, the parametric expression of which is written as follows:  
\[\left[\begin{array}{c}x\\ y\\ z\end{array}\right]=\left[\begin{array}{c}a_{1}\cos^{\varepsilon 1}\eta\cos^{ \varepsilon 2}\omega\\ a_{2}\cos^{\varepsilon 1}\eta\sin^{\varepsilon 2}\omega\\ a_{3}\sin^{\varepsilon 1}\eta\end{array}\right],\begin{array}{c}-\frac{\pi}{2} \leq\eta\leq\frac{\pi}{2}\\ -\pi\leq\omega<\pi\end{array} \tag{12}\]  
where \(x\), \(y\), and \(z\) are the coordinates of a point on the superquadric, \(a_{1}\), \(a_{2}\), and \(a_{3}\) are the dimensions of the superquadric on the various axes, and \(\varepsilon_{1}\) and \(\varepsilon_{2}\) represent the shape of the superquadric.  
Using the above equation, we could derive the inside-outside function \(F\), as shown in Equation (13). This equation could be used to determine whether a given point was on the inside or outside of the superquadric. For instance, \(F=1\) meant that the point was on the surface of the superquadric, whereas \(F<1\) and \(F>1\) indicated that the point was on the inside and outside of the superquadric, respectively.  
\[F(x,y,z)=\left(\left(\frac{x}{a_{1}}\right)^{\frac{2}{\varepsilon 2}}+\left(\frac{y}{a_{2}}\right)^{\frac{2}{ \varepsilon 2}}\right)^{\frac{\varepsilon 2}{\varepsilon 1}}+\left(\frac{z}{a_{3}} \right)^{\frac{2}{\varepsilon 1}} \tag{13}\]  
However, the above equation relied on the fact that the center of the superquadric lied at the origin and that the coordinate axes were aligned with the world coordinate axes. In the real world, the world coordinates of an object are different from the model coordinates, which means that a rotation matrix \(\mathbf{R}\) and translation matrix \(\mathbf{t}\) are required to convert the world coordinates of the point cloud of the real object into model coordinates. Suppose that world coordinate point \(\mathbf{X}\) becomes model coordinate point \(\mathbf{x}\) after conversion:  
\[\mathbf{X}=\left[\mathbf{R}|\mathbf{t}|\mathbf{x}\right. \tag{14}\]  
\[\mathbf{x}=\left[\mathbf{R}|\mathbf{t}\right]^{-1}\mathbf{X} \tag{15}\]  
Thus, expressing the superquadric model of an object in the real world requires at least 11 parameters:  
\[F(x_{w},y_{w},z_{w})=F(x_{w},y_{w},z_{w}; \tag{16}\]  
\[a_{1},a_{2},a_{3},\varepsilon_{1},\varepsilon_{2},f,\theta,\psi,p_{x},p_{y},p _{z})\]  
where \(\theta,f,\psi\) are the parameters of the rotation matrix, and \(p_{x},p_{y},p_{z}\) are the parameters of the translation matrix. Below, we express these 11 parameters using the following set: \(\Lambda=\{\lambda_{1},\lambda_{2},L,\lambda_{11}\}\).  
We employed the Levenberg-Marquardt (LM) algorithm to obtain the optimal solution for the parameters of point group shapes by minimizing the value of the equation:  
\[\underset{\Lambda}{min}\sum_{i=1}^{n}\left(F(x_{i},y_{i},z_{i};\lambda_{1}, \ldots,\lambda_{11})-1\right)^{2} \tag{17}\]  
However, the LM approach produces a local optimal solution and is extremely sensitive to initial parameter settings. To illustrate the influence of the initial optimization parameters, we randomly selected the following initial parameters:  
\[\begin{array}{c}a_{1}=0.5,a_{2}=0.5,a_{3}=0.5,\varepsilon_{1}=1,\varepsilon_ {2}=1,\\ f=0^{\circ},\theta=0^{\circ},\psi=0^{\circ},p_{x}=0,p_{y}=0,p_{z}=0\end{array}\]  
This means performing optimization without choosing suitable initial parameter settings. Figure 8 presents the simulation results, in which the white points indicate the model that needs to be estimated and the red points are the estimation results. Clearly, deviations in the initial parameters and model to be estimated can result in significant simulation errors.