math

pymethods.math.approximate_basis(vectors: numpy.array) → numpy.array

approximate the basis for the input vectors

Args:

vectors (np.array): M Vectors x N Dimensions

Returns:

np.array: N Dimensions x N Dimensions

pymethods.math.least_squares_fitting_of_two_point_sets(vector_a: numpy.array, vector_b: numpy.array) → Tuple[numpy.array]

estimate rigd transform required to move vector_a such that it overlaps vector_b

http://nghiaho.com/?page_id=671

Args:

vector_a (np.array): N dimensions x M points vector_b (np.array): N dimensions x M points

Returns:

Tuple[np.array]: [rotation, translation] matrices

pymethods.math.dot(vector_a: numpy.array, vector_b: numpy.array) → float
Args:

vector_a (np.ndarray): vector_b (np.ndarray):

Returns:

np.ndarray:

pymethods.math.vector_project(vector_a: numpy.array, vector_b: numpy.array) → numpy.array

project vector_a onto vector_b

https://math.oregonstate.edu/home/programs/undergrad/CalculusQuestStudyGuides/vcalc/dotprod/dotprod.html

Args:

vector_a (np.array): M vectors x N dimensions or N dimensions array vector_b (np.array): M vectors x N dimensions or N dimensions array

Returns:

np.array: M vectors x N dimensions or N dimensions array

pymethods.math.project_to_plane(vectors: numpy.array, normal: numpy.array) → numpy.array

project the vectors to plane described by vector, this is unscaled

Args:

vectors (np.array): M vectors x N dimensions normal (np.array): 1 x N dimensions or N dimensions

Returns:

np.array: M vectors x N dimensions

pymethods.math.change_basis(x: numpy.array, basis: numpy.array) → numpy.array

https://en.wikiversity.org/wiki/Tensors/Transformation_rule_under_a_change_of_basis] Best Vid on change of reference frames https://www.youtube.com/watch?v=P2LTAUO1TdA

Args:

x (np.array): M vectors x N dimensions basis (np.array): N dimensions x N dimensions

Returns:

np.array: M vectors x N dimensions

pymethods.math.rotation_matrix(vector: numpy.array, angle: float) → numpy.array

calculate rotation matrix required to rotate points about vector by phi https://en.wikipedia.org/wiki/Rotation_matrix

Args:

vector (np.array): 3 dimension axis of rotation angle (np.float): radians, angle to rotate around vector right hand

rule

Returns:

np.array: 3 x 3 rotation matrix

pymethods.math.frennet_serret(centreline: numpy.array) → numpy.array

frennet_serret [summary]

calculate the frennet serret frames https://en.wikipedia.org/wiki/Frenet%E2%80%93Serret_formulas

Args:

centreline (np.array): M vectors x N dimensions

Returns:
np.array: Normal, Binormal, Tangent of curve

3 x N dimensions x N dimensions

pymethods.math.frennet_serret_with_transport(centreline: numpy.array) → numpy.array

calcualate frennet frames https://janakiev.com/blog/framing-parametric-curves/

Args:

centreline (np.array): N x M points

Returns:
np.array: Normal, Binormal, Tangent of curve

3 x N dimensions x N dimensions

pymethods.math.cart2pol(vectors: numpy.array, returnRad=False) → numpy.array

convert N x 2 nd array from cartesian to polar

Args:

vectors (np.array): 2 dimensions x M vectors

Returns:

np.array: 2 dimensions x M vectors

pymethods.math.pol2cart(vectors: numpy.array) → numpy.array

convert N x 2 ndarray from polar to cartesian

Args:

vectors (np.array): M vectors x 2 dimensions

Returns:

np.array: M vectors x 2 dimensions

pymethods.math.all_diameters(contour: numpy.array) → float

for a contour in 2d calculate all the diameters

Args:

contour (np.array): M vectors x N dimensions

Returns:

np.float: diameter

pymethods.math.area_assumed_diameter(contour: numpy.array) → float

calculate the area assumed diameter

Args:

contour (np.array): M vectors x N dimensions

Returns:

np.float: diameter

pymethods.math.is_linearly_dependent(*args: Tuple[numpy.array]) → bool

takes in either a single np.array of vectors or *args of vectors and checks whether they are linearly dependent

Returns:

bool:

pymethods.math.make_linearly_independent(vectors: numpy.ndarray, out=False) → numpy.ndarray

gets the set of linearly independent vector from a set of vectors

Args:

vectors (np.ndarray): N dimensions x M points

Returns:

np.ndarray:

pymethods.math.vector_perpendicular(vectors_a: numpy.ndarray, vectors_b: numpy.ndarray) → numpy.ndarray

perpendiculr_vectors

calculate the component of vector_a perpendicular to vector_b

Args:

vectors_a (np.ndarray): [description] vectors_b (np.ndarray): [description]

Returns:

np.ndarray: [description]

pymethods.math.smallest_angle_between_vectors(vectors_a: numpy.ndarray, vectors_b: numpy.ndarray, direction=None) → numpy.ndarray

angle_between_vectors

calculate the angle between two vectors in radians

Args:

vectors_a (np.ndarray): N dimensions x M Vectors vectors_b (np.ndarray): N dimensions x M or 1 Vectors basis (np.ndarray): basis indicating how the

angle should be calculated

Returns:

np.ndarray: array containing the angles of the vectors

pymethods.math.directed_angle(vector_a: numpy.ndarray, vector_b: numpy.ndarray, direction: numpy.ndarray) → numpy.ndarray

calculate the angle however use information from a direction, for example the normal, to determine the correct angle. The angle is calculated counter clockwise from the direction.

Args:

vector_a (np.ndarray): vector_b (np.ndarray): direction (np.ndarray): normal direction

Returns:

np.ndarray: array of angles

pymethods.math.minimum_bounding_box(array: numpy.ndarray) → numpy.ndarray

Calculate the minumim bounding box for an array of points

Args:

array (np.ndarray): N dimensions x M points

Returns:

np.ndarray: N dimensions x 2 points

pymethods.math.mean_square(array: numpy.array) → numpy.array
Args:

array (np.array):

Returns:

np.array:

pymethods.math.mean_square_error(array_a: numpy.array, array_b: numpy.array) → numpy.array

https://en.wikipedia.org/wiki/Mean_squared_error

Args:

array_a (np.array): array_b (np.array):

pymethods.math.cross(vectors_a: numpy.array, vectors_b: numpy.array) → numpy.array

cross product, if single vector it is faster to hard code the cross product rather than use the np.cross method. Thus, if a single vector is passed through the hardcoded method is applied.

Args:

vectors_a (np.array): vectors_b (np.array):

Returns:

np.array: crossed vectors

pymethods.math.make_3d(vectors: numpy.array) → numpy.array

For an 2 x N array convert it into 3 x N by concatenating a 0 column vector of length end

Args:

vectors (np.array): 2 dimensions x M vectors

Returns:

np.array: 3 dimensions x M vectors

pymethods.math.skew_symmetric_3d(vector: numpy.array) → numpy.array

https://en.wikipedia.org/wiki/Skew-symmetric_matrix

Args:

vector (np.array): 1 x N dimension or N Dimension

Returns:

np.array: N dimension x N dimension array

pymethods.math.l2_norm(vector_a: numpy.array, keepdims=True) → Union[float, numpy.array]

calculates the l2_norm commonly associated with the magnitude of a vector.

Args:
vector_a (np.array): N dimension or M Vector x N dimension

array

method (str): string specifying which method to use

Returns:

Union[np.float, np.array]: l2_norm of input vector/vectors

pymethods.math.mean(vector_a: numpy.array) → Union[float, numpy.array]
Args:
vector_a (np.array): N dimension or M Vector x N dimension

array

Returns:

Union[np.float, np.array]: mean of input vector/vectors

pymethods.math.close_curve(contour: numpy.array, write_end=False) → numpy.array

Assume input is a closed contour. Check the 0 and -1 indices. If they are not the same append 0 to the array

Args:

contour (np.array): N dimension contour x M vectors

Returns:

np.array: N dimension contour x M vectors or M + 1 vectors

pymethods.math.area(contour: numpy.array) → float

calculate area of closed 2d contour

Args:

contour (np.array): M points x N dimensions

Returns:

np.float: area

pymethods.math.contour_centroid(contour: numpy.array, axis=0) → numpy.array

get_centroid_of_cross_section

get centroid of a closed contour using 2d greene’s theorem by projectiing it onto the basis in 2d

https://leancrew.com/all-this/2018/01/greens-theorem-and-section-properties/

Args:

contour ([nd.array]): N x M points basis ([nd.array]): 3 x 3 matrix of where the contour lies

Returns:

np.array: 1 x 3 location of centroid

pymethods.math.normalize(vector_a: numpy.array) → numpy.array
Args:

vector_a (np.array): N dimension array x M Vectors

Returns:

np.array: N dimension array x M Vectors

pymethods.math.scalar_project(vector_a: numpy.array, vector_b: numpy.array, *kwargs: dict) → numpy.array

https://math.oregonstate.edu/home/programs/undergrad/CalculusQuestStudyGuides/vcalc/dotprod/dotprod.html

Args:

vector_a (np.array): N dimensions x M vectors vector_b (np.array): N dimensions x M, 1, 3 vectors

Returns:

np.array: M vectors x N dimensions or N dimensions array

pymethods.math.order_basis(vectors: numpy.array, basis: numpy.array) → numpy.array

we want the basis to be ordered in [[i], [j], [k]]. i and j can be arbitrary however k must be consistent and should point normal to the plane

Args:

vectors (np.array): M Vectors x N dimension array basis (np.array): 3 Vectors x N dimension array

Returns:

np.array: 3 Vectors x N dimension array

pymethods.math.approximate_normal(vectors: numpy.array) → numpy.array

approximate the normal for the input vectors

Args:

vectors (np.array): M Vectors x N Dimensions

Returns:

np.array: N Dimensions

pymethods.math.argSortByBasis(array, ref_basis, n_to_check=20)

arg_basis_sort [summary]

For an ndarray describing the points along a closed contour and a ref_basis which describes the plane outpud the ids of the sorted points. The points are sorted such that the ndarray[0,:] is the point closest to the i-axis and the orientation of rotation is determined by the closest point

Args:
ndarray (_np.ndarray)N x M matrix where N is the number of points

and M is the total number of dimensions

ref_basis (_np.ndarray): 3 x 3 basis matrix discribing return_ref (bool, optional): return a copy of ndarray in the

ref_basis frame. Defaults to True.

Returns:

_np.ndarray: list of sorted indices

pymethods.math.sortByBasis(self, returnBasis=False, ref_basis=None)

arg_basis_sort

For an ndarray describing the points along a closed contour and a ref_basis which describes the plane, return the sorted points. The points are sorted such that ndarray[0,:] is the point closest to the i-axis of ref_basis and the points in increasing order describe a rotation in the clockwise direction of the given ref_basis.

Args:
ndarray (_np.ndarray)N x M matrix where N is the number of points

and M is the total number of dimensions

ref_basis (_np.ndarray): 3 x 3 basis matrix discribing n_to_check (int, optional): number of points to check for

clockwise rotation. Number of points should not be beyond the j-axis as the orientation will be flipped. Defaults to 20.

Returns:

_np.ndarray: list of sorted points