vector

Routines for working with vectors These routines can be used with vectors, as well as with matrices containing a vector in each row.

Functions

Details

Routines for working with vectors These routines can be used with vectors, as well as with matrices containing a vector in each row.

vector.GramSchmidt(p1, p2, p3)[source]

Gram-Schmidt orthogonalization

Parameters:

p1 : array (3,) or (M,3)

coordinates of Point 1

p2 : array (3,) or (M,3)

coordinates of Point 2

p3 : array (3,) or (M,3)

coordinates of Point 3

Returns:

Rmat : array (9,) or (M,9)

flattened rotation matrix

Notes

The flattened rotation matrix corresponds to

\[\mathbf{R} = [ \vec{e}_1 \, \vec{e}_2 \, \vec{e}_3 ]\]
vector.angle(v1, v2)[source]

Angle between two vectors

Parameters:

v1 : array (N,) or (M,N)

vector 1

v2 : array (N,) or (M,N)

vector 2

Returns:

angle : double or array(M,)

angle between v1 and v2

Notes

\[\alpha =arccos(\frac{\vec{v_1} \cdot \vec{v_2}}{| \vec{v_1} | \cdot | \vec{v_2}|})\]
vector.plane_orientation(p1, p2, p3)[source]

The vector perpendicular to the plane defined by three points.

Parameters:

p1 : array (3,) or (M,3)

coordinates of Point 1

p2 : array (3,) or (M,3)

coordinates of Point 2

p3 : array (3,) or (M,3)

coordinates of Point 3

Returns:

n : array (3,) or (M,3)

vector perpendicular to the plane

Notes

\[\vec{n} = \frac{ \vec{a} \times \vec{b}} {| \vec{a} \times \vec{b}|}\]
vector.project(v1, v2)[source]

Project one vector onto another

Parameters:

v1 : array (N,) or (M,N)

projected vector

v2 : array (N,) or (M,N)

target vector

Returns:

v_projected : array (N,) or (M,N)

projection of v1 onto v2

Notes

\[\vec{n} = \frac{ \vec{a} }{| \vec{a} |}\]\[\vec{v}_{proj} = \vec{n} (\vec{v} \cdot \vec{n})\]
vector.qrotate(v1, v2)[source]

Quaternion indicating the shortest rotation from one vector into another. You can read “qrotate” as either “quaternion rotate” or as “quick rotate”.

Parameters:

v1 : ndarray (3,)

first vector

v2 : ndarray (3,)

second vector

Returns:

q : ndarray (3,)

quaternion rotating v1 into v2

vector.rotate_vector(vector, q)[source]

Rotates a vector, according to the given quaternions. Note that a single vector can be rotated into many orientations; or a row of vectors can all be rotated by a single quaternion.

Parameters:

vector : array, shape (3,) or (N,3)

vector(s) to be rotated.

q : array_like, shape ([3,4],) or (N,[3,4])

quaternions or quaternion vectors.

Returns:

rotated : array, shape (3,) or (N,3)

rotated vector(s)

Notes

\[q \circ \left( {\vec x \cdot \vec I} \right) \circ {q^{ - 1}} = \left( {{\bf{R}} \cdot \vec x} \right) \cdot \vec I\]

More info under http://en.wikipedia.org/wiki/Quaternion

Examples

>>> mymat = eye(3)
>>> myVector = r_[1,0,0]
>>> quats = array([[0,0, sin(0.1)],[0, sin(0.2), 0]])
>>> quat.rotate_vector(myVector, quats)
array([[ 0.98006658,  0.19866933,  0.        ],
       [ 0.92106099,  0.        , -0.38941834]])
>>> quat.rotate_vector(mymat, [0, 0, sin(0.1)])
array([[ 0.98006658,  0.19866933,  0.        ],
       [-0.19866933,  0.98006658,  0.        ],
       [ 0.        ,  0.        ,  1.        ]])