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:
  • normal – length-3 np.float_ – The orthonormal basis output will span the plane perpendicular to normal.
  • ref_vec – length-3 np.float_, optional – If specified, on1 will be the normalized projection of ref_vec onto the plane perpendicular to normal. Default is None.
Returns:

  • on1 – length-3 np.float_ – First vector defining the orthonormal basis in the plane normal to normal
  • on2 – length-3 np.float_ – Second vector defining the orthonormal basis in the plane normal to normal

Raises:
  • ValueError – If normal or ref_vec is not expressible as a 1-D vector with 3 elements
  • VectorError – (typecode NONPRL) 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.
  • tolnp.float_, optional – Tolerance for deviation of dot products from one or zero. Default value is opan.const.DEF.ORTHONORM_TOL.
  • reportbool, optional – Whether to record and return vectors / vector pairs failing the orthonormality condition. Default is False.
Returns:

  • obool – Indicates whether column vectors of a are orthonormal to within tolerance tol.

  • n_faillist of int, or None

    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_faillist of 2-tuples of int, or None

    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:

opan.utils.vector.parallel_check(vec1, vec2)

Checks whether two vectors are parallel OR anti-parallel.

Vectors must be of the same dimension.

Parameters:
  • vec1 – length-R np.float_ – First vector to compare
  • vec2 – length-R np.float_ – Second vector to compare
Returns:

parboolTrue if (anti-)parallel to within opan.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:
  • vec – length-R np.float_ – Vector to project
  • vec_onto – length-R np.float_ – Vector onto which vec is to be projected
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:
  • vec – length-R np.float_ – Vector to reject
  • vec_onto – length-R np.float_ – Vector onto which vec is to be rejected
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:
  • vec1 – length-R np.float_ – First vector
  • vec2 – length-R np.float_ – Second vector
Returns:

anglenp.float_ – Angle between the two vectors in degrees