amep.utils.unit_vector_2D#
- amep.utils.unit_vector_2D(theta: float | ndarray) ndarray #
Generates 2D unit vectors in the x-y plane with angle theta to the x axis.
- Parameters:
theta (float or np.ndarray) – Angle in degrees. A single value can be given as a float or multiple values as an array of shape (N,).
- Returns:
Unit vector(s).
- Return type:
np.ndarray
Examples
>>> import amep >>> import numpy as np >>> print(amep.utils.unit_vector_2D(60)) [0.5 0.8660254 0. ] >>> theta = np.array([0, 60, 120, 180, 240, 300, 360]) >>> vectors = amep.utils.unit_vector_2D(theta) >>> fig, axs = amep.plot.new(figsize=(3,3)) >>> axs.scatter(vectors[:,0], vectors[:,1], s=50) >>> axs.set_xlabel(r'$x$') >>> axs.set_ylabel(r'$y$') >>> axs.axhline(0, c='k', lw=1, ls='--') >>> axs.axvline(0, c='k', lw=1, ls='--') >>> fig.savefig('./figures/utils/utils-unit_vector_2D.png') >>>