netsse.tools.kinematics
=======================

.. py:module:: netsse.tools.kinematics

.. autoapi-nested-parse::

   Functions to manipulate the **body kinematics** of, e.g., marine vessels.

   .. dropdown:: Copyright (C) 2023-2026 Technical University of Denmark, R.E.G. Mounet
       :color: primary
       :icon: law

       *This code is part of the NetSSE software.*

       NetSSE is free software: you can redistribute it and/or modify it under
       the terms of the GNU General Public License as published by the Free
       Software Foundation, either version 3 of the License, or (at your
       option) any later version.

       NetSSE is distributed in the hope that it will be useful, but WITHOUT
       ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       for more details.

       You should have received a copy of the GNU General Public License along
       with this program.  If not, see https://www.gnu.org/licenses/.

       To credit the author, users are encouraged to use below reference:

       .. code-block:: text

           Mounet, R. E. G., & Nielsen, U. D. NetSSE: An open-source Python package
           for network-based sea state estimation from ships, buoys, and other
           observation platforms (version 2.2). Technical University of Denmark,
           GitLab. February 2026. https://doi.org/10.11583/DTU.26379811.

   *Last updated on 20-02-2026 by R.E.G. Mounet*



Functions
---------

.. autoapisummary::

   netsse.tools.kinematics.Rzyx
   netsse.tools.kinematics.Tzyx
   netsse.tools.kinematics.accel_rigid_body
   netsse.tools.kinematics.eulerang


Module Contents
---------------

.. py:function:: Rzyx(phi, theta, psi)

   Computes the Euler angle rotation matrix :math:`R` using the `zyx` convention,
   as per Fossen (2011).

   .. note::
       This function can be used to transform velocity vectors from a body-fixed frame to the North-East-Down (NED) reference frame, using specified Euler angles.

   :param phi: Roll angle [rad].
   :type phi: Scalar, or numpy array of size (N,) or (N,M)
   :param theta: Pitch angle [rad].
   :type theta: Scalar, or numpy array of size (N,) or (N,M)
   :param psi: Yaw angle [rad].
   :type psi: Scalar, or numpy array of size (N,) or (N,M)

   :returns: **R** -- Euler angle rotation matrix :math:`R`.
   :rtype: Numpy array of size (shape(phi),3,3)

   .. seealso::

      :py:obj:`Tzyx`
          Euler angle transformation matrix for attitude.

      :py:obj:`eulerang`
          Euler angle transformation matrix in full.

   .. rubric:: References

   Fossen, T. I. (2011). *Handbook of Marine Craft Hydrodynamics and Motion Control.*
   John Wiley and Sons.

   .. rubric:: Example

   >>> R = Rzyx(phi, theta, psi)


.. py:function:: Tzyx(phi, theta)

   Computes the Euler angle transformation matrix :math:`T` for attitude using the `zyx` convention, as per Fossen (2011).

   .. note::
       This function can be used to transform velocity vectors from a body-fixed frame to the North-East-Down (NED) reference frame, using specified Euler angles.

   :param phi: Roll angle [rad].
   :type phi: Scalar, or numpy array of size (N,) or (N,M)
   :param theta: Pitch angle [rad].
   :type theta: Scalar, or numpy array of size (N,) or (N,M)

   :raises ValueError: The :math:`T` matrix has a singularity for :math:`\theta = \pm 90^\circ`.

   :returns: **T** -- Euler angle transformation matrix :math:`T` for attitude.
   :rtype: Numpy array of size (shape(phi),3,3)

   .. seealso::

      :py:obj:`Rzyx`
          Euler angle rotation matrix.

      :py:obj:`eulerang`
          Euler angle transformation matrix.

   .. rubric:: References

   Fossen, T. I. (2011). *Handbook of Marine Craft Hydrodynamics and Motion Control.*
   John Wiley and Sons.

   .. rubric:: Example

   >>> T = Tzyx(phi, theta)


.. py:function:: accel_rigid_body(a_O, r_P, omega, omega_dot, axis=0)

   Calculates the acceleration :math:`a_P` of a point P in a rigid body.

   The acceleration, :math:`a_O` of a point O in the rigid body, as well as the body's angular velocity, :math:`\omega`, and acceleration, :math:`\dot{\omega}`, are assumed to be known.

   :param a_O: Linear acceleration vector of the reference point O [m/s²].
   :type a_O: Numpy array of vector of size (_,3,_)
   :param r_P: Position vector of point P relative to the reference point O [m].
   :type r_P: Numpy vector of size (3,)
   :param omega: Angular velocity vector [rad/s].
   :type omega: Numpy array of vector of size (_,3,_)
   :param omega_dot: Angular acceleration vector [rad/s²].
   :type omega_dot: Numpy array of vector of size (_,3,_)
   :param axis: Axis along which to compute the cross products. Default is 0.
   :type axis: int, optional

   :returns: **a_P** -- Linear acceleration vector of the target point P [m/s²].
   :rtype: Numpy array of size (_,3,_)

   .. rubric:: Example

   >>> a_P = accel_rigid_body(a_O, r_P, omega, omega_dot)


.. py:function:: eulerang(phi, theta, psi, unit='rad')

   Computes the Euler angle transformation matrix :math:`J` in full using the `zyx`
   convention, as per Fossen (2011):

   .. math::
       J =
       \left[
           \begin{array}{cc}
               J_1 & 0 \newline
               0 & J_2
           \end{array}
       \right],

   where :math:`J_1 = R_{zyx}` and :math:`J_2 = T_{zyx}`.

   .. note::
       This function can be used to transform velocity vectors from a body-fixed frame to the North-East-Down (NED) reference frame, using specified Euler angles.

   :param phi: Roll angle.
   :type phi: Scalar, or numpy array of size (N,) or (N,M)
   :param theta: Pitch angle.
   :type theta: Scalar, or numpy array of size (N,) or (N,M)
   :param psi: Yaw angle.
   :type psi: Scalar, or numpy array of size (N,) or (N,M)
   :param unit: Unit of the input angles ``phi``, ``theta``, and ``psi``.
   :type unit: {'rad','deg'}, optional

   :returns: * **J** (*Numpy array of size (shape(phi),6,6)*) -- Euler angle transformation matrix.
             * **J1** (*Numpy array of size (shape(phi),3,3)*) -- :math:`J_1 = R_{zyx}`, the Euler angle rotation matrix.
             * **J2** (*Numpy array of size (shape(phi),3,3)*) -- :math:`J_2 = T_{zyx}`, the Euler angle transformation matrix for attitude.

   .. seealso::

      :py:obj:`Rzyx`
          Euler angle rotation matrix.

      :py:obj:`Tzyx`
          Euler angle transformation matrix for attitude.

   .. rubric:: References

   Fossen, T. I. (2011). *Handbook of Marine Craft Hydrodynamics and Motion Control.*
   John Wiley and Sons.

   .. rubric:: Example

   >>> [J, Rzyx, Tzyx] = eulerang(phi, theta, psi)


