# Superellipsoid

In mathematics, a superellipsoid (or super-ellipsoid) is a solid whose horizontal sections are superellipses (Lamé curves) with the same squareness parameter $\epsilon _{2}$, and whose vertical sections through the center are superellipses with the squareness parameter $\epsilon _{1}$. It is a generalization of an ellipsoid, which is a special case when $\epsilon _{1}=\epsilon _{2}=1$.
Superellipsoids as computer graphics primitives were popularized by Alan H. Barr (who used the name "superquadrics" to refer to both superellipsoids and supertoroids). In modern computer vision and robotics literatures, superquadrics and superellipsoids are used interchangeably, since superellipsoids are the most representative and widely utilized shape among all the superquadrics.
Superellipsoids have an rich shape vocabulary, including cuboids, cylinders, ellipsoids, octahedra and their intermediates. It becomes an important geometric primitive widely used in computer vision, robotics, and physical simulation. The main advantage of describing objects and envirionment with superellipsoids is its conciseness and expressiveness in shape. Furthermore, a closed-form expression of the Minkowski sum between two superellipsoids is available. This makes it a desirable geometric primitive for robot grasping, collision detection, and motion planning.

## Special cases

A handful of notable mathematical figures can arise as special cases of superellipsoids given the correct set of values, which are depicted in the above graphic:
* Cylinder
* Sphere
* Steinmetz solid
* Bicone
* Regular octahedron
* Cube, as a limiting case where the exponents tend to infinity
Piet Hein's supereggs are also special cases of superellipsoids.

## Formulas
### Basic (normalized) superellipsoid

The basic superellipsoid is defined by the implicit function
    $f(x,y,z)=\left(x^{\frac {2}{\epsilon _{2}}}+y^{\frac {2}{\epsilon _{2}}}\right)^{\epsilon _{2}/\epsilon _{1}}+z^{\frac {2}{\epsilon _{1}}}$
The parameters $\epsilon _{1}$ and $\epsilon _{2}$ are positive real numbers that control the squareness of the shape.
The surface of the superellipsoid is defined by the equation:
$f(x,y,z)=1$
For any given point $(x,y,z)\in \mathbb {R} ^{3}$, the point lies inside the superellipsoid if $f(x,y,z)<1$, and outside if $f(x,y,z)>1$.
Any "parallel of latitude" of the superellipsoid (a horizontal section at any constant z between -1 and +1) is a Lamé curve with exponent $2/\epsilon _{2}$, scaled by $a=(1-z^{\frac {2}{\epsilon _{1}}})^{\frac {\epsilon _{1}}{2}}$, which is
    $\left({\frac {x}{a}}\right)^{\frac {2}{\epsilon _{2}}}+\left({\frac {y}{a}}\right)^{\frac {2}{\epsilon _{2}}}=1.$
Any "meridian of longitude" (a section by any vertical plane through the origin) is a Lamé curve with exponent $2/\epsilon _{1}$, stretched horizontally by a factor w that depends on the sectioning plane. Namely, if $x=u\cos \theta$ and $y=u\sin \theta$, for a given $\theta$, then the section is
    $\left({\frac {u}{w}}\right)^{\frac {2}{\epsilon _{1}}}+z^{\frac {2}{\epsilon _{1}}}=1,$
where
    $w=(\cos ^{\frac {2}{\epsilon _{2}}}\theta +\sin ^{\frac {2}{\epsilon _{2}}}\theta )^{-{\frac {\epsilon _{2}}{2}}}.$
In particular, if $\epsilon _{2}$ is 1, the horizontal cross-sections are circles, and the horizontal stretching $w$ of the vertical sections is 1 for all planes. In that case, the superellipsoid is a solid of revolution, obtained by rotating the Lamé curve with exponent $2/\epsilon _{1}$ around the vertical axis.

### Superellipsoid

The basic shape above extends from −1 to +1 along each coordinate axis. The general superellipsoid is obtained by scaling the basic shape along each axis by factors $a_{x}$, $a_{y}$, $a_{z}$, the semi-diameters of the resulting solid. The implicit function is
    $F(x,y,z)=\left(\left({\frac {x}{a_{x}}}\right)^{\frac {2}{\epsilon _{2}}}+\left({\frac {y}{a_{y}}}\right)^{\frac {2}{\epsilon _{2}}}\right)^{\frac {\epsilon _{2}}{\epsilon _{1}}}+\left({\frac {z}{a_{z}}}\right)^{\frac {2}{\epsilon _{1}}}$.
Similarly, the surface of the superellipsoid is defined by the equation
$F(x,y,z)=1$
For any given point $(x,y,z)\in \mathbb {R} ^{3}$, the point lies inside the superellipsoid if $f(x,y,z)<1$, and outside if $f(x,y,z)>1$.
Therefore, the implicit function is also called the inside-outside function of the superellipsoid.
The superellipsoid has a parametric representation in terms of surface parameters $\eta \in [-\pi /2,\pi /2)$, $\omega \in [-\pi ,\pi )$.
    $x(\eta ,\omega )=a_{x}\cos ^{\epsilon _{1}}\eta \cos ^{\epsilon _{2}}\omega$
    $y(\eta ,\omega )=a_{y}\cos ^{\epsilon _{1}}\eta \sin ^{\epsilon _{2}}\omega$
    $z(\eta ,\omega )=a_{z}\sin ^{\epsilon _{1}}\eta$

### General posed superellipsoid

In computer vision and robotic applications, a superellipsoid with a general pose in the 3D Euclidean space is usually of more interest.
For a given Euclidean transformation of the superellipsoid frame $g=[\mathbf {R} \in SO(3),\mathbf {t} \in \mathbb {R} ^{3}]\in SE(3)$ relative to the world frame, the implicit function of a general posed superellipsoid surface defined the world frame is
$F\left(g^{-1}\circ (x,y,z)\right)=1$
where $\circ$ is the transformation operation that maps the point $(x,y,z)\in \mathbb {R} ^{3}$ in the world frame into the canonical superellipsoid frame.

### Volume of superellipsoid

The volume encompassed by the superelllipsoid surface can be expressed in terms of the beta functions $\beta (\cdot ,\cdot )$,
$V(\epsilon _{1},\epsilon _{2},a_{x},a_{y},a_{z})=2a_{x}a_{y}a_{z}\epsilon _{1}\epsilon _{2}\beta ({\frac {\epsilon _{1}}{2}},\epsilon _{1}+1)\beta ({\frac {\epsilon _{2}}{2}},{\frac {\epsilon _{2}+2}{2}})$
or equivalently with the Gamma function $\Gamma (\cdot )$, since
$\beta (m,n)={\frac {\Gamma (m)\Gamma (n)}{\Gamma (m+n)}}$

## Recovery from data

Recoverying the superellipsoid (or superquadrics) representation from raw data (e.g., point cloud, mesh, images, and voxels) is an important task in computer vision, robotics, and physical simulation.
Traditional computational methods model the problem as a least-square problem. The goal is to find out the optimal set of superellipsoid parameters $\theta \doteq [\epsilon _{1},\epsilon _{2},a_{x},a_{y},a_{z},g]$ that minimize an objective function. Other than the shape parameters, $g\in$ SE(3) is the pose of the superellipsoid frame with respect to the world coordinate.
There are two commonly used objective functions. The first one is constructed directly based on the implicit function
$G_{1}(\theta )=a_{x}a_{y}a_{z}\sum _{i=1}^{N}\left(F^{\epsilon _{1}}\left(g^{-1}\circ (x_{i},y_{i},z_{i})\right)-1\right)^{2}$
The minimization of the objective function provides a recovered superellipsoid as close as possible to all the input points $\{(x_{i},y_{i},z_{i})\in \mathbb {R} ^{3},i=1,2,...,N\}$. At the mean time, the scalar value $a_{x},a_{y},a_{z}$ is positively proportional to the volume of the superellipsoid, and thus have the effect of minimizing the volume as well.
The other objective function tries to minimized the radial distance between the points and the superellipsoid. That is
$G_{2}(\theta )=\sum _{i=1}^{N}\left(\left|r_{i}\right|\left|1-F^{-{\frac {\epsilon _{1}}{2}}}\left(g^{-1}\circ (x_{i},y_{i},z_{i})\right)\right|\right)^{2}$, where $r_{i}=\|(x_{i},y_{i},z_{i})\|_{2}$
A probabilistic method called EMS is designed to deal with noise and outliers. In this method, the superellipsoid recovery is reformulated as a maximum likelihood estimation problem, and an optimization method is proposed to avoid local minima utilizing geometric similarities of the superellipsoids.
The method is further extended by modeling with nonparametric bayesian techniques to recovery multiple superellipsoids simultaneously.