skrobot.coordinates.math.skew_symmetric_matrix

skrobot.coordinates.math.skew_symmetric_matrix(v)[source]

Returns skew-symmetric matrix of given vector v.

This function creates a skew-symmetric matrix (also known as an antisymmetric matrix) that represents the cross product operation as matrix multiplication. For any vectors a and v, the cross product v x a is equivalent to the matrix-vector product of the skew-symmetric matrix of v and the vector a.

v × a = skew_symmetric_matrix(v) @ a

\[\begin{split}\left( \begin{array}{ccc} 0 & -v_2 & v_1 \\ v_2 & 0 & -v_0 \\ -v_1 & v_0 & 0 \end{array} \right)\end{split}\]
Parameters:

v (numpy.ndarray or list) – 3D vector [v0, v1, v2]

Returns:

matrix – 3x3 skew-symmetric matrix.

Return type:

numpy.ndarray

Examples

>>> from skrobot.coordinates.math import skew_symmetric_matrix
>>> skew_symmetric_matrix([1, 2, 3])
array([[ 0, -3,  2],
       [ 3,  0, -1],
       [-2,  1,  0]])
>>> # Verify cross product equivalence: v x a = [v]x @ a
>>> import numpy as np
>>> v = np.array([0, 1, 0])  # vector j
>>> a = np.array([1, 0, 0])  # vector i
>>>
>>> # Expected result of v x a (j x i) is -k = [0, 0, -1]
>>> cross_result = np.cross(v, a)
>>> matrix_result = skew_symmetric_matrix(v) @ a
>>>
>>> print(f"np.cross(v, a) = {cross_result}")
np.cross(v, a) = [ 0  0 -1]
>>> print(f"skew_symmetric_matrix(v) @ a = {matrix_result}")
skew_symmetric_matrix(v) @ a = [ 0.  0. -1.]
>>>
>>> np.allclose(cross_result, matrix_result)
True