% -*-latex-*-

\title{Orbiter Technical Notes: Inertia calculations for composite vessels}
\author{<NAME>}
\date{September 28, 2017}

\documentclass[a4paper]{article}
\usepackage[dvips]{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{cite}
\usepackage{setspace}
\usepackage{times}

\newcommand\mat[1]{\mathsf{#1}}

\begin{document}
\maketitle

\section{Introduction}
This document describes the method Orbiter uses to define the inertial behaviour for composite vessels from the parameters of its components.

\section{Definitions}
To describe the dynamics of a rigid body we use Euler's rotation equations that describe the rotation of the body in the rotating system:
\begin{equation}
\mat{I} \dot{\vec{\omega}} + \vec{\omega} \times (\mat{I}\vec{\omega}) = \vec{M}
\end{equation}
where $\vec{\omega}$ are the components of angular velocity around the three main vessel axes, $\vec{M}$ are the applied torques, and $\mat{I}$ is the inertia matrix.

In the principal body frame, the inertia matrix is diagonal, where diagonal elements $I_n\;(n=1,2,3)$ are the principal moments of inertia (PMI). We then get
\begin{equation}
\begin{split}
  I_1 \dot\omega_1 + (I_3 - I_2) \omega_2 \omega_3 &= M_1 \\
  I_2 \dot\omega_2 + (I_1 - I_3) \omega_3 \omega_1 &= M_2 \\
  I_3 \dot\omega_3 + (I_2 - I_1) \omega_1 \omega_2 &= M_3
\end{split}
\end{equation}
Note that Orbiter assumes vessels to be defined in the principal frame but does not enforce it, that is, only the diagonal elements of $\mat{I}$ are considered. For most vessel layouts, an intrinsic symmetry is present, and the vessel frame naturally aligns closely with the principal frame, so that neglecting the off-diagonal elements of $\mat{I}$ incurs a small error. For composite structures this may not be true, so a more general framework may be introduced in the future. 

\section{Composite structures}
In spaceflight scenarios, rigid structures may commonly be formed by connecting individual components (launch stack composed from individual stages, spacecraft docked at a space station, Apollo CSM+LM assembly, etc.) These rigid assemblies act as a single body under rotation, governed by its own composite PMI.

While the composite PMI may be pre-calculated for commonly encountered arrangements, not all combinations are predictable. In Orbiter, any vessels with suitable docking ports can be connected to form arbitrary new ``super-vessels'' of two or more components. It is therefore necessary to find a method to compute the composite PMI from the inertia parameters of the individual components and the geometry of the assembly.
Orbiter uses the following method:
\begin{itemize}
\item Represent a vessel by a small number of discrete point masses arranged so that they generate the same PMI as the original vessel.
\item Transform the point masses of all individual vessels into the common barycentric frame of the super-vessel.
\item Compute the PMI of the super-vessel by summing over the point masses of all individual components.
\end{itemize}

\subsection{Point mass representation of a vessel}
In general, the PMI components of an object occupying a volume $V$ with mass density distribution $\rho(\vec{r}),\; \vec{r}\in V$ are given by
\begin{equation}
\begin{split}
  I_1 &= \int_V \rho(\vec{r}) (y^2 + z^2) d\vec{r} \\
  I_2 &= \int_V \rho(\vec{r}) (z^2 + x^2) d\vec{r} \\
  I_3 &= \int_V \rho(\vec{r}) (x^2 + y^2) d\vec{r}
\end{split}
\end{equation}
with $\vec{r} = \lbrace x,y,z \rbrace$.
For an object composed of $n$ individual point masses $m_i$ at locations $\vec{r}_i$ this simplifies to
\begin{equation}
\begin{split}
  I_1 &= \sum_{i=1}^n m_i (y_i^2 + z_i^2) \\
  I_2 &= \sum_{i=1}^n m_i (z_i^2 + x_i^2) \\
  I_3 &= \sum_{i=1}^n m_i (x_i^2 + y_i^2)
\end{split}
\end{equation}

We can now represent a vessel with arbitrary PMI values by 6 point masses that produce the same PMI values:
\begin{equation}
\begin{split}
  \hat{\vec{r}}_{1,2} &= \lbrace \pm \hat x, 0, 0 \rbrace \\
  \hat{\vec{r}}_{3,4} &= \lbrace 0, \pm \hat y, 0 \rbrace \\
  \hat{\vec{r}}_{5,6} &= \lbrace 0, 0, \pm \hat z \rbrace
\end{split}
\end{equation}
and $m_i = \hat m = m/6,\; i=1..6$, given vessel mass $m$.
To compute the axis offsets $\hat x, \hat y, \hat z$ of the point masses we note that
\begin{equation}
\begin{split}
  I_1 &= \hat m (2 \hat y^2 + 2 \hat z^2) \\
  I_2 &= \hat m (2 \hat z^2 + 2 \hat x^2) \\
  I_3 &= \hat m (2 \hat x^2 + 2 \hat y^2)
\end{split}
\end{equation}
and thus
\begin{equation}\label{eq:smp_ofs}
\begin{split}
\hat x &= \frac{1}{2} \sqrt{\left| -\frac{I_1}{\hat m} + \frac{I_2}{\hat m} + \frac{I_3}{\hat m} \right|} \\
\hat y &= \frac{1}{2} \sqrt{\left| \frac{I_1}{\hat m} - \frac{I_2}{\hat m} + \frac{I_3}{\hat m} \right|} \\
\hat z &= \frac{1}{2} \sqrt{\left| \frac{I_1}{\hat m} + \frac{I_2}{\hat m} - \frac{I_3}{\hat m} \right|}.
\end{split}
\end{equation}
It is left to the reader to confirm that this point sample arrangement generates the correct PMI values.

\subsection{Super-vessel definition}
A super-vessel is a composite structure arranged by rigid assembly of individual vessels where the geometry is defined by the position and orientation of the participating docking ports of the component vessels.

The origin of the super-vessel frame is given by the barycentre of the assembly. It should be noted that the origin can shift continuously relative to the vessel assembly if the masses of the component vessels change (e.g. as a result of fuel consumption).

The orientation of the super-vessel frame is currently arbitrarily set to the orientation of the first vessel in the assembly. No attempt is made to rotate to the principal frame. This may need some thought.

With this arrangement, we can define transformations for each component vessel $j$ into the supervessel frame:
\begin{equation}
  \vec{r}_j^S = \mat{R}_j \vec{r}_j + \vec{r}_j^0,
\end{equation}
where $\mat{R}_j$ is a rotation matrix and $\vec{r}_j^0$ is the position of the vessel CoG in the super-vessel frame.
The transformation of the point-mass representations of all participating vessels into the super-vessel frame is given by
\begin{equation}
\hat{\vec{r}}_{ji}^S = \mat{R}_j \hat{\vec{r}}_{ji} + \vec{r}_j^0, \; j=1..N, \; i=1..6,
\end{equation}
where $N$ is the number of participating vessels.
We can now assemble the components $I_n^S$ of the super-vessel PMI by summing over the point samples of all vessels:
\begin{equation}
\begin{split}
I_1^S & = \sum_{j=1}^N \sum_{i=1}^6 \hat m_j ([\hat y_{ji}^S]^2 + [\hat z_{ji}^S]^2)\\
I_2^S & = \sum_{j=1}^N \sum_{i=1}^6 \hat m_j ([\hat z_{ji}^S]^2 + [\hat x_{ji}^S]^2)\\
I_3^S & = \sum_{j=1}^N \sum_{i=1}^6 \hat m_j ([\hat x_{ji}^S]^2 + [\hat y_{ji}^S]^2)
\end{split}
\end{equation}

\section{Mass-normalised PMI}
It should be noted that Orbiter uses \emph{mass-normalised} PMI values $\tilde I_n = I_n/m$, which has the advantage that PMI values can remain unchanged even if the vessel mass changes. All Orbiter API calls by convention return and expect $\tilde I_n$ instead of $I_n$. Applying this convention to the super-vessel definition yields
\begin{equation}
\tilde{I}_n^S = \frac{I_n^S}{\sum_{j=1}^N m_j}
\end{equation}
Likewise, for the computation of the sample offsets in Eq.~\ref{eq:smp_ofs} we can write
\begin{equation}
  \hat x = \frac{1}{2} \sqrt{\left| -\frac{\tilde{I}_1 m}{\hat m} + \frac{\tilde{I}_2 m}{\hat m} + \frac{\tilde{I}_3 m}{\hat m} \right|} =
  \sqrt{\frac{3}{2} \left| -\tilde{I}_1 + \tilde{I}_2 + \tilde{I}_3 \right|}
\end{equation}
with corresponding expressions for $\hat y$ and $\hat z$.

\end{document}
