Convert Ellipsoid from Cov and Mean to Quadric Representation Question
I have an ellipsoid represented as a Covariance $\Sigma \in \mathbb{R}^{3\times3}$ and a mean centroid $\mu\in \mathbb{R}^{3}$. I want to represent it as a homogenous quadric, which is a $4\times4$ symmetric matrix. A quadric fulfills the property $\hat{x}^{\top}Q\hat{x}=0$ for all points $\hat{x} = [x^\top;1]^{\top}$ on the surface of the ellipsoid.
Background
This post describes how to convert a Covariance to quadric form but assumes $\mu=0$. I tried setting $b=\mu, c=-1$, but that does not work.
I specifically need it in this form, as I want to project in onto a conic like so $C^{*}=PQ^{*}P^\top$ in the next step.
Does anyone know how to adapt the quadric if the Ellipsoid is not zero-centered?
Update
I tried to derive the Quadric parametrization from a given $(\Sigma, \mu)$.
We can define the $\sigma$-surface of this ellipsoid:
$$(x-\mu)^\top\Sigma^{-1}(x-\mu)-\sigma=0$$
It can also be described with the general quadric equation:
$$x^{\top}Ax+2b^{\top}x+c=0$$
By multiplying out the first equation and comparing the constant, linear and quadratic terms, the following correspondances between the parameters can be established:
$$A=\Sigma^{-1}, b=-A\mu ,\; c=\mu^⊤\mu-\sigma$$
The general quadric equation can be expressed more compact with homogenous formulation:
$$Q = \begin{bmatrix}A & b \\ b^⊤ & c\end{bmatrix}, $$
$$ \hat{x}^{\top}Q\hat{x}=0, \hat{x}=[x^{\top},1]^{\top}$$
Remaining Problem (Example)
For an axis-aligned, non zero-centered Ellipsoid parametrized by
$$\Sigma=\begin{bmatrix}2 & 0 & 0\\ 0 & 1 & 0 \\ 0 & 0 & 1\end{bmatrix}, \mu=[1, 1, 1]^\top$$
the resulting quadric looks like this
$$Q=\begin{bmatrix}
0.5 & 0  & 0 & -0.5\\
0  & 1 &  0 & -1 \\
0  & 0 &  1 & -1\\
-0.5 & -1 & -1 &  2 
\end{bmatrix}$$.
The problem is, that the equation $\hat{x}^{\top}Q\hat{x}=0$ is not fulfilled anymore:
$$\hat{x} = [3, 1, 1, 1]\rightarrow \hat{x}^{\top}Q\hat{x}= 1.5$$
$$\hat{x} = [1, 2, 1, 1]\rightarrow \hat{x}^{\top}Q\hat{x}= 0.5$$
$$\hat{x} = [1, 1, 2, 1]\rightarrow \hat{x}^{\top}Q\hat{x}= 0.5$$
Am I missing something? This Colab Notebook shows the code I used to test this all. Feel free to leave a comment.
 A: Ah! you are all perfectly correct till the last few equations. One of the three probe points is wrong, it's not on the ellipsoid, so it got a different value.
The correct coordinate for the first point shall be
$$
\hat{x} = [1+\sqrt 2, 1, 1, 1]\rightarrow \hat{x}^{\top}Q\hat{x}= 0.5
$$
Key is to notice, $\Sigma$ is the covariance, not standard deviation, the extant of the axis shall be sqrt ed.

In your code, this line is wrong
ellipsoid_m1 = (Sigma @ unit_sphere_ijk) + mu[:, np.newaxis]

Recall that to generate a Gaussian random variable of covariance $\Sigma$, you should not use $\Sigma$ to transform standard Gaussian. Instead you need to use its Cholesky factor to transform the standard normal variable.
$$
\Sigma=AA^T\\
z\sim N(0,I)\\
Az\sim N(0,AA^T)
$$

Really nice that you provide that well made colab notebook! it makes verifying your work super easy.
A: Derivation error
First there is an error in the derivation of the coefficient $c$. The general form:
$$(x-\mu)^\top\Sigma^{-1}(x-\mu)-\sigma=0$$
multiplies out to
$$x^{\top}\Sigma^{-1}x-2\mu^{\top}\Sigma^{-1}x+\mu^{\top}\Sigma^{-1}\mu-\sigma=0$$
which yields the coefficients by comparison
$$A=\Sigma^{-1}, b=-\Sigma^{-1}\mu ,\; c=\mu^⊤\Sigma^{-1}\mu-\sigma$$
Eigenvalue vs. Radius
As pointed out by @Binxu Wang in her answer the samples on the $\sigma$-surface of an ellipsoid with known Covariance $\Sigma$ are obtained from the samples on the unit-sphere $\hat{x}$ by
$$x = L\hat{x} + \mu$$
where L is the Cholesky Decomposition of $\Sigma$
$$\Sigma = LL^{\top}$$
Sampling with $\Sigma$ instead of $L$ would give points on the $\sigma^2$-surface of the ellipsoid.
Result
I verified, that all samples on the Ellipsoid fulfill $x^{\top}Qx=0$.
