yt.utilities.math_utils.ortho_find

yt.utilities.math_utils.ortho_find(vec1)[source]

Find two complementary orthonormal vectors to a given vector.

For any given non-zero vector, there are infinite pairs of vectors orthonormal to it. This function gives you one arbitrary pair from that set along with the normalized version of the original vector.

Parameters:

vec1 : array_like

An array or list to represent a 3-vector.

Returns:

vec1 : array

The original 3-vector array after having been normalized.

vec2 : array

A 3-vector array which is orthonormal to vec1.

vec3 : array

A 3-vector array which is orthonormal to vec1 and vec2.

Raises:

ValueError :

If input vector is the zero vector.

Notes

Our initial vector is vec1 which consists of 3 components: x1, y1, and z1. ortho_find determines a vector, vec2, which is orthonormal to vec1 by finding a vector which has a zero-value dot-product with vec1.

vec1 \cdot vec2 = x_1 x_2 + y_1 y_2 + z_1 z_2 = 0

As a starting point, we arbitrarily choose vec2 to have x2 = 1, y2 = 0:

vec1 \cdot vec2 = x_1 + (z_1 z_2) = 0 

\rightarrow z_2 = -(x_1 / z_1)

Of course, this will fail if z1 = 0, in which case, let’s say use z2 = 1 and x2 = 0:

\rightarrow y_2 = -(z_1 / y_1)

Similarly, if y1 = 0, this case will fail, in which case we use y2 = 1 and z2 = 0:

\rightarrow x_2 = -(y_1 / x_1)

Since we don’t allow vec1 to be zero, all cases are accounted for.

Producing vec3, the complementary orthonormal vector to vec1 and vec2 is accomplished by simply taking the cross product of vec1 and vec2.

Examples

>>> a = [1.0, 2.0, 3.0]
>>> a, b, c = ortho_find(a)
>>> a
array([ 0.26726124,  0.53452248,  0.80178373])
>>> b
array([ 0.9486833 ,  0.        , -0.31622777])
>>> c
array([-0.16903085,  0.84515425, -0.50709255])