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
|
---|---|
Returns: | vec1 : array
vec2 : array
vec3 : array
|
Raises: | ValueError :
|
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.
As a starting point, we arbitrarily choose vec2 to have x2 = 1, y2 = 0:
Of course, this will fail if z1 = 0, in which case, let’s say use z2 = 1 and x2 = 0:
Similarly, if y1 = 0, this case will fail, in which case we use y2 = 1 and z2 = 0:
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])