opan.utils.vector¶
Submodule for miscellaneous vector operations
Functions implemented here are (to the best of this author’s knowledge) not available in NumPy or SciPy.
Functions
-
opan.utils.vector.
ortho_basis
(normal[, ref_vec])¶ Generates an orthonormal basis in the plane perpendicular to normal
The orthonormal basis generated spans the plane defined with normal as its normal vector. The handedness of on1 and on2 in the returned basis is such that:
\[\mathsf{on1} \times \mathsf{on2} = {\mathsf{normal} \over \left\| \mathsf{normal}\right\|}\]normal must be expressible as a one-dimensional
np.array
of length 3.Parameters: Returns: Raises: ValueError
– If normal or ref_vec is not expressible as a 1-D vector with 3 elementsVectorError
– (typecodeNONPRL
) If ref_vec is specified and it is insufficiently non- parallel with respect to normal
-
opan.utils.vector.
orthonorm_check
(a[, tol[, report]])¶ Checks orthonormality of the column vectors of a matrix.
If a one-dimensional
np.array
is passed to a, it is treated as a single column vector, rather than a row matrix of length-one column vectors.The matrix a does not need to be square, though it must have at least as many rows as columns, since orthonormality is only possible in N-space with a set of no more than N vectors. (This condition is not directly checked.)
Parameters: - a – R x S
np.float_
– 2-D array of column vectors to be checked for orthonormality. - tol –
np.float_
, optional – Tolerance for deviation of dot products from one or zero. Default value isopan.const.DEF.ORTHONORM_TOL
. - report –
bool
, optional – Whether to record and return vectors / vector pairs failing the orthonormality condition. Default isFalse
.
Returns: o –
bool
– Indicates whether column vectors of a are orthonormal to within tolerance tol.n_fail –
list
ofint
, orNone
–If report ==
True
:A list of indices of column vectors failing the normality condition, or an empty list if all vectors are normalized.
If report ==
False
:o_fail –
list
of 2-tuples ofint
, orNone
–If report ==
True
:A list of 2-tuples of indices of column vectors failing the orthogonality condition, or an empty list if all vectors are orthogonal.
If report ==
False
:
- a – R x S
-
opan.utils.vector.
parallel_check
(vec1, vec2)¶ Checks whether two vectors are parallel OR anti-parallel.
Vectors must be of the same dimension.
Parameters: Returns: par –
bool
–True
if (anti-)parallel to withinopan.const.PRM.NON_PARALLEL_TOL
degrees.False
otherwise.
-
opan.utils.vector.
proj
(vec, vec_onto)¶ Vector projection.
Calculated as:
\[\mathsf{vec\_onto} * \frac{\mathsf{vec}\cdot\mathsf{vec\_onto}} {\mathsf{vec\_onto}\cdot\mathsf{vec\_onto}}\]Parameters: Returns: proj_vec – length-R
np.float_
– Projection of vec onto vec_onto
-
opan.utils.vector.
rej
(vec, vec_onto)¶ Vector rejection.
Calculated by subtracting from vec the projection of vec onto vec_onto:
\[\mathsf{vec} - \mathrm{proj}\left(\mathsf{vec}, \ \mathsf{vec\_onto}\right)\]Parameters: Returns: rej_vec – length-R
np.float_
– Rejection of vec onto vec_onto
-
opan.utils.vector.
vec_angle
(vec1, vec2)¶ Angle between two R-dimensional vectors.
Angle calculated as:
\[\arccos\left[ \frac{\mathsf{vec1}\cdot\mathsf{vec2}} {\left\|\mathsf{vec1}\right\| \left\|\mathsf{vec2}\right\|} \right]\]Parameters: Returns: angle –
np.float_
– Angle between the two vectors in degrees