vestacrystparser.utilities

Miscellaneous utility functions, such as string parsing and matrix algebra.

vestacrystparser.utilities.invert_matrix(mat: list[list[float]]) list[list[float]]

Inverts a 3x3 matrix.

vestacrystparser.utilities.matmul(mat1: list[list[float]], mat2: list[list[float]]) list[list[float]]

Multiplies two matrices (NxM) x (MxL) -> (NxL)

vestacrystparser.utilities.parallel_vectors(v1: list[float], v2: list[float]) bool

Tests if two vectors are parallel or antiparellel.

vestacrystparser.utilities.parse_line(line: str) list[int | float | str]

Split a line into tokens and convert each token.

Parameters:

line – String with data separated by spaces.

Returns:

A list of tokens (int, float, or string, as appropriate).

vestacrystparser.utilities.parse_token(token: str) int | float | str

Convert a token to int or float if possible (or leave as a string).

Parameters:

token – A string.

Returns:

token converted to int if possible, or else float if possible, or else returned as-is.

vestacrystparser.utilities.transpose(mat: list[list]) list[list]

Transposes a matrix.

vestacrystparser.utilities.unit_vector(v: list[float]) list[float]

Normalises vector v to unit length.

vestacrystparser.utilities.vector_cross(v1: list[float], v2: list[float]) list[float]

Takes the cross product of two 3-vectors

vestacrystparser.utilities.vector_dot(v1: list[float], v2: list[float]) float

Takes the dot product of two vectors.