12. vector

This module is used to manipulate arrays of 3D vectors, assumed to be numpy arrays of shape (..., 3).

mag and dot include alternate versions (mag1 and dot1) which keep the last dimension index. This is useful when you intend to multiply or divide a vector by a result, e.g.:

normed_vector = vector / mag1(vector)

Note that using mag in this case will trigger an error, because the arrays are not aligned.

12.1. Overview

mag(X) Calculate the length of an array of vectors.
mag1(X) Calculate the length of an array of vectors, keeping the last dimension index.
dot(X, Y) Calculate the dot product of two arrays of vectors.
dot1(X, Y) Calculate the dot product of two arrays of vectors, keeping the last
norm(X) Computes a normalized version of an array of vectors.
plus(X) Return a shifted version of an array of vectors.
minus(X) Return a shifted version of an array of vectors.
cross(X, Y) Return the cross-product of two vectors.
proj(X, Y) Return the projection of one vector onto another.
apply_basis(X, B) Transform each vector into the specified basis/bases.
midpoint_delta(X) Returns center point and vector of each edge of the polygon defined by the points.
arb_perp(V) For each vector, return an arbitrary vector that is perpendicular.
vec([x, y, z]) Generate a [..., 3] vector from seperate x, y, z.
rot(a[, X, cutoff]) Rotate points around an arbitrary axis.
normalize_basis(B) Create right-handed orthonormal basis/bases from input basis.

12.2. Functions

ilpm.vector.mag(X)[source]

Calculate the length of an array of vectors.

ilpm.vector.mag1(X)[source]

Calculate the length of an array of vectors, keeping the last dimension index.

ilpm.vector.dot(X, Y)[source]

Calculate the dot product of two arrays of vectors.

ilpm.vector.dot1(X, Y)[source]

Calculate the dot product of two arrays of vectors, keeping the last dimension index

ilpm.vector.norm(X)[source]

Computes a normalized version of an array of vectors.

ilpm.vector.plus(X)[source]

Return a shifted version of an array of vectors.

ilpm.vector.minus(X)[source]

Return a shifted version of an array of vectors.

ilpm.vector.cross(X, Y)[source]

Return the cross-product of two vectors.

ilpm.vector.proj(X, Y)[source]

Return the projection of one vector onto another.

Parameters:

X, Y : vector array

Returns:

Z : vector array

\(\vec{Z} = \frac{\vec{X} \cdot \vec{Y}}{|Y|^2} \vec{Y}\)

ilpm.vector.midpoint_delta(X)[source]

Returns center point and vector of each edge of the polygon defined by the points.

ilpm.vector.arb_perp(V)[source]

For each vector, return an arbitrary vector that is perpendicular.

Note: arbitrary does not mean random!

ilpm.vector.apply_basis(X, B)[source]

Transform each vector into the specified basis/bases.

Parameters:

X : vector array, shape [..., 3]

B : orthonormal basis array, shape [..., 3, 3]

Returns:

Y : vector array, shape [..., 3]

X transformed into the basis given by B

ilpm.vector.vec(x=[0], y=[0], z=[0])[source]

Generate a [..., 3] vector from seperate x, y, z.

Parameters:

x, y, z: array

coordinates; default to 0, may have any shape

Returns:

X : [..., 3] array

ilpm.vector.rot(a, X=None, cutoff=1e-10)[source]

Rotate points around an arbitrary axis.

Parameters:

a : [..., 3] array

Rotation vector, will rotate counter-clockwise around axis by an amount given be the length of the vector (in radians). May be a single vector or an array of vectors if each point is rotated separately.

X : [..., 3] array

Vectors to rotate; if not specified generates a rotation basis instead.

cutoff : float

If length of vector less than this value (1E-10 by default), no rotation is performed. (Used to avoid basis errors)

Returns:

Y : [..., 3] array

Rotated vectors or rotation basis.

ilpm.vector.normalize_basis(B)[source]

Create right-handed orthonormal basis/bases from input basis.

Parameters:

B : [..., 1-3, 3] array

input basis, should be at least 2d. If the second to last axis has 1 vectors, it will automatically create an arbitrary orthonormal basis with the specified first vector. (note: even if three bases are specified, the last is always ignored, and is generated by a cross product of the first two.)

Returns:

NB : [..., 3, 3] array

orthonormal basis