```
// ===========================================================================
/**
* \defgroup vec Vectors and matrices
* Vectors and matrices are used to represent positions, velocities, translations,
* rotations, etc. in the 3-dimensional object space. Orbiter provides the
* %VECTOR3 and %MATRIX3 structures for 3-D vectors and matrices. A number
* of utility functions allow common operations such as matrix-vector
* products, dot and vector products, etc.
*/
// ===========================================================================
//@{
/**
* \brief 3-element vector
*/
typedef union {
double data[3]; ///< array data interface
struct { double x, y, z; }; ///< named data interface
} VECTOR3;
/**
* \brief 3x3-element matrix
*/
typedef union {
double data[9]; ///< array data interface (row-sorted)
struct { double m11, m12, m13, m21, m22, m23, m31, m32, m33; }; ///< named data interface
} MATRIX3;
//@}
// ======================================================================
// Some helper functions
// ======================================================================
/**
* \ingroup vec
* \brief Vector composition
*
* Returns a vector composed of the three provided arguments
* \param x x-component
* \param y y-component
* \param z z-component
* \return vector defined as (x,y,z)
*/
inline VECTOR3 _V(double x, double y, double z)
{
VECTOR3 vec = {x,y,z}; return vec;
}
/**
* \ingroup vec
* \brief Matrix composition
*
* Returns a matrix composed of the provided elements.
* \return
* \f$
* \left(\begin{array}{ccc}
* m_{11} & m_{12} & m_{13} \\
* m_{21} & m_{22} & m_{23} \\
* m_{31} & m_{32} & m_{33}
* \end{array}\right)
* \f$
*/
inline MATRIX3 _M(double m11, double m12, double m13,
double m21, double m22, double m23,
double m31, double m32, double m33)
{
MATRIX3 mat = {m11,m12,m13, m21,m22,m23, m31,m32,m33}; return mat;
}
/**
* \ingroup vec
* \brief Matrix-vector multiplication
* \param[in] A matrix operand
* \param[in] b vector operand
* \return Result of <b>Ab</b>
*/
inline VECTOR3 mul (const MATRIX3 &A, const VECTOR3 &b)
{
return _V (
A.m11*b.x + A.m12*b.y + A.m13*b.z,
A.m21*b.x + A.m22*b.y + A.m23*b.z,
A.m31*b.x + A.m32*b.y + A.m33*b.z);
}
```