# Util module¶

## ¶

The poliastro.core.util module contains, mainly, a set of functions realted to vectorial computations.

poliastro.core.util.circular_velocity

Compute circular velocity for a given body given thegravitational parameter and the semimajor axis.

$v = \sqrt{\frac{\mu}{a}}$
Parameters: k (float) – Gravitational Parameter a (float) – Semimajor Axis
poliastro.core.util.rotate

Rotates a vector around axis x, y or z a Counter ClockWise angle.

$\begin{split}R(\theta) = \begin{bmatrix} \cos(\theta) & -\sin(\theta) \\ \sin(\theta) & \cos(\theta) \end{bmatrix}\end{split}$
Parameters: vec (ndarray) – Dimension 3 vector. angle (float) – Angle of rotation (rad). axis (int) – Axis to be rotated (X-axis: 0, Y-axis: 1, Z-axis: 2)

Note

This performs a so-called active or alibi transformation: rotates the vector while the coordinate system remains unchanged. To do the opposite operation (passive or alias transformation) call the function as rotate(vec, ax, -angle) or use the convenience function transform.

References

http://en.wikipedia.org/wiki/Rotation_matrix#Ambiguities

poliastro.core.util.transform

Rotates a coordinate system around axis a positive right-handed angle.

Note

This is a convenience function, equivalent to rotate(vec, ax, -angle). Refer to the documentation of that function for further information.

poliastro.core.util.norm

Returns the norm of a 3 dimension vector.

$\left \| \vec{v} \right \| = \sqrt{\sum_{i=1}^{n}v_{i}^2}$
Parameters: vec (ndarray) – Dimension 3 vector.

Examples

>>> from poliastro.core.util import norm
>>> from astropy import units as u
>>> vec = [1, 1, 1] * u.m
>>> norm(vec)
1.7320508075688772

poliastro.core.util.cross

Computes cross product between two vectors.

$\begin{split}\vec{w} = \vec{u} \times \vec{v} = \begin{vmatrix} u_{y} & y_{z} \\ v_{y} & v_{z} \end{vmatrix}\vec{i} - \begin{vmatrix} u_{x} & u_{z} \\ v_{x} & v_{z} \end{vmatrix}\vec{j} + \begin{vmatrix} u_{x} & u_{y} \\ v_{x} & v_{y} \end{vmatrix}\vec{k}\end{split}$
Parameters: a (ndarray) – 3 Dimension vector. b (ndarray) – 3 Dimension vector.

Examples

>>> from poliastro.core.util import cross
>>> from astropy import units as u
>>> i = [1, 0, 0] * u.m
>>> j = [0, 1, 0] * u.m
>>> cross(i, j)
array([0., 0., 1.])


Note

np.cross is not supported in numba nopython mode, see https://github.com/numba/numba/issues/2978