ref_ellipse¶
- giant.ray_tracer.utilities.ref_ellipse(verts)[source]¶
This function finds the best fit ellipsoid to a set of vertices (minimizing the algebraic distance residuals).
This is done by solving the least squares equation
\[\begin{split}\left[\begin{array}{ccccccccc} \mathbf{x}^2+\mathbf{y}^2-2\mathbf{z}^2 & \mathbf{x}^2 + \mathbf{z}^2 - 2\mathbf{y}^2 & 2\mathbf{x}*\mathbf{y} & 2\mathbf{x}*\mathbf{z} & 2\mathbf{y}*\mathbf{z} & 2\mathbf{x} & 2\mathbf{y} & 2\mathbf{z} & \mathbf{1} \end{array}\right]\left[\begin{array}{c} A\\ B \\ C \\ D \\ E \\ F \\ G \\ H \\ I\end{array}\right] = \mathbf{x}^2+\mathbf{y}^2+\mathbf{z}^2\end{split}\]Given the solution, we then form the matrix
\[\begin{split}\mathbf{A} = \left[\begin{array}{cccc} A+B+C-1 & C & D & F \\ C & A-2B-1 & E & G \\ D & E & B-2A-1 & H \\ F & G & H & I \end{array}\right]\end{split}\]We then have that the center of the ellipse is found by solving the 3x3 system
\[\begin{split}-\mathbf{A}_{0:2,0:2}\mathbf{c} = \left[\begin{array}{ccc} F \\ G \\ H \end{array}\right]\end{split}\]and the ellipsoid matrix is found according to
\[\begin{split}\mathbf{T} = \left[\begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ c_0 & c_1 & c_2 & 1\end{array}\right] \\ \mathbf{R} = \mathbf{T}\mathbf{A}\mathbf{T}^T \\ \mathbf{E} = -\frac{\mathbf{R}_{0:3,0:3}}{r_{3,3}}\end{split}\]where \(\mathbf{E}\) is the ellipsoid matrix.