How can I find the centroid of left and right side part of ellipsoid to cross section plane. Here is the code and image which I tried.
[x,y,z]=ellipsoid(0,0,0,0.5,1,0.25,50);
direction = [1 0 0];
figure
h=surfl(x,y,z);
set(h,'facealpha',0.5)
shading interp
xlabel('x')
ylabel('y')
zlabel('z')
hold on
s=patch([1 -1 -1 1], [1 1 -1 -1], [0 0 0 0]) ;
rotate(s,direction,120)
The general equation of an ellipsoid is
$ (r - r_0)^T Q (r - r_0) = 1 \hspace{24pt} (1)$
where $r = [x, y, z]^T$ and $r_0$ is the center of the ellipsoid.
The idea that I am presenting in this solution is as follows:
Use an affine transformation to transform the ellipsoid into a unit sphere centered at the origin. Then apply the same transformation to the cutting plane. Now find the two centroids of the portions of the sphere on both sides of the transformed cutting plane. Finally apply the inverse of the affine transformation to the centroids you obtained, this will give the centroids of the two portions of the ellipsoid on both sides of the original cutting plane.
To that end, first diagonalize $Q$ as $Q = R D R^T$
where the diagonal matrix $D$ entries are the reciprocals of the squares of the semi-axes lengths, namely,
$D = \begin{bmatrix} \dfrac{1}{a^2} && 0 && 0 \\ 0 && \dfrac{1}{b^2} && 0 \\ 0 && 0 && \dfrac{1}{c^2} \end{bmatrix} $
And the rotation matrix $R$ contains the corresponding unit direction vectors of the three axes of the ellipsoid.
By splitting the positive definite matrix $D$ as $D^{1/2} D^{1/2}$, one can define a change of variables (affine transformation) as follows:
$r = r_0 + R D^{-1/2} r' \hspace{12pt} (2) $
where the vector $r'$ is the new variable.
Substituting (2) into the equation of the ellipsoid results in
$r'^T r' = 1 $
Thus with the transformation define by (2), we have transformed our ellipsoid into a unit sphere centered at the origin.
Next, if the cutting plane equation is $n^T (r - t n) = 0$ where $n$ is a unit vector, and $t$ is a scalar, then plugging in (2) results in the new equation of the transformed plane that cuts the unit sphere. Its equation is
$ n^T (r_0 + R D^{-1/2} r' ) = t $
which after simple manipulation, becomes,
$ (D^{-1/2} R^T n)^T r' = t - n^T r_0 $
which is of the form $ n'^T r' = t' $
This plane cuts the sphere into two (unequal) portions.
The idea as stated above is to find the centroid of these portions of the sphere, then apply the inverse of the affine transformation will give us the centroids of the original portions of the ellipsoid.
It is convenient that we only need to calculate one centroid, while the other one follows directly because the overall centroid of both portions is at the origin.
To find centroid of the portion pointed to (from the origin) by $n'$, we find the distance between the origin and the plane, this is given by
$ d = \dfrac{t'}{\sqrt{n'^T n'}} = \dfrac{ t - n^T r_0}{\sqrt {n^T Q^{-1} n}} \hspace{12pt} (3)$
Having obtained the signed distance between the center of the unit sphere (which is the origin) and its cutting plane, we can proceed to find the distance along the normal to the cutting plane where the centroid lies. Let this direction be along the $z$ axis, then the "$z$" coordinate of the centroid is
$ z_1 = \displaystyle \dfrac{ \int_{z = d}^{1} \pi z (1 - z^2) dz }{\int_{z = d}^{1} \pi (1 - z^2) dz }$
So that,
$ z_1 = \dfrac{ (1 - d) - \dfrac{1}{4} (1 - d^4) } { (1 - d) - \dfrac{1}{3} ( 1- d^3) }$
Simplifying, this becomes,
$ z_1 = \dfrac{ 1 - \frac{1}{4} (1 + d + d^2 + d^3) }{ 1 - \frac{1}{3}(1 + d + d^2) }$
Therefore the centeroid of the portion of the unit sphere pointed to by $n'$ is
$r'_1 = z_1 \dfrac{n'}{|n'|} $
From which we can calculate the centroid of the other portion, because
$ V'_1 r'_1 + V'_2 r'_2 = 0 $
Here, $V'_1 = \pi (1 - d - \frac{1}{3} (1 - d^3) ) $
and $V'_2 = \dfrac{4 \pi}{3} - V'_1 $
This leads directly to the value of the vector $r'_2 $
Finally we have to apply the inverse of the transformation that we performed, and using (2) , we get
$r_1 = r_0 + R D^{-1/2} r'_1, \ r_2 = r_0 + R D^{-1/2} r'_2 $
as the centroids of the two portions of the ellipsoid.