Use of quaternions and frame transformation matrices
The following examples show many ways to compute the "qsw" local orbital frame (see Local frames for more details).
The objective is not so much the computation of the local frame as the illustration of the use of functions related to quaternions and frame transformation matrices. The notations used are:
mat_qsw: frame transformation matrix from the inertial frame to the "qsw" local orbital frame. Multiplying by mat_qsw changes coordinates from the inertial frame to the "qsw" local frame.
q_qsw: quaternion of the rotation that transforms the axes of the inertial frame into the axes of the "qsw" local orbital frame. Applying the rotation q_qsw to a vector defined in the inertial frame gives the components of the rotated vector in the same frame. Applying the rotation q_qsw is also equivalent to changing components from the "qsw" local frame to the inertial frame. Note that q_qsw and -q_qsw correspond to the same rotation.
Note: First execute the code snippet below to initialize variables.
1) Local frame from position and velocity (frame transformation matrices)
2) Local frame from orbital elements (frame transformation matrices)
3) Local frame from orbital elements (quaternions)
4) Local frame from orbital elements (quaternions in inertial frame)
5) Local frame from right ascension, declination, "bearing" (quaternions)
6) Local frame in 2 successive rotations (quaternions)