Numpy cross product does not return orthogonal vector

1k Views Asked by At

I am using the cross product in numpy to generate a third vector orthogonal to two orthogonal vectors. In the code snippet below, the first operation (cross product) shows my problem, taking the cross product of two vectors gives me just the negation of one of the input vectors, not a third vector orthogonal to both.

The next operation shows that my two vectors are indeed orthogonal, not that this should matter. What's going on here?

np.cross([ 0.36195593,  0.93219521,  0.        ],[ 0.65916161, -0.25594151, -0.70710672])
Out[94]: array([-0.6591615 ,  0.25594147, -0.70710684])

np.dot([ 0.36195593,  0.93219521,  0.        ],[ 0.65916161, -0.25594151, -0.70710672])
Out[95]: 3.905680168170278e-09
1

There are 1 best solutions below

0
On BEST ANSWER

First, it's isn't exactly the negation. The last term has the same sign. It just so happens, perfectly coincidentally, that it is close to the negation of one of the original vectors.

Secondly, it is the correct cross product. Instead of doing it by hand, I'll appeal to the fact that the cross product is defined geometrically as a vector that must be orthogonal to its two original inputs. The fact that the two inputs are orthogonal is (largely) irrelevant.

In [11]: first = [ 0.36195593,  0.93219521,  0.]

In [12]: second = [ 0.65916161, -0.25594151, -0.70710672]

In [13]: third = np.cross(first, second)

In [14]: third
Out[14]: array([-0.6591615 ,  0.25594147, -0.70710684])

In [15]: np.dot(first, third)
Out[15]: 0.0

In [17]: np.dot(second, third)
Out[17]: 1.1102230246251565e-16

In [18]: np.isclose( np.dot(second, third), 0)
Out[18]: True

HTH.