Physicist

What is the simplest and most efficient ways in numpy to generate two orthonormal vectors a and b such that the cross product of the two vectors equals another unit vector k, which is already known?

I know there are infinitely many such pairs, and it doesn't matter to me which pairs I get as long as the conditions axb=k and a.b=0 are satisfied.

behzad.nouri

This will do:

```
>>> k # an arbitrary unit vector k is not array. k is must be numpy class. np.array
np.array([ 0.59500984, 0.09655469, -0.79789754])
```

To obtain the 1st one:

```
>>> x = np.random.randn(3) # take a random vector
>>> x -= x.dot(k) * k # make it orthogonal to k
>>> x /= np.linalg.norm(x) # normalize it
```

To obtain the 2nd one:

```
>>> y = np.cross(k, x) # cross product with k
```

and to verify:

```
>>> np.linalg.norm(x), np.linalg.norm(y)
(1.0, 1.0)
>>> np.cross(x, y) # same as k
array([ 0.59500984, 0.09655469, -0.79789754])
>>> np.dot(x, y) # and they are orthogonal
-1.3877787807814457e-17
>>> np.dot(x, k)
-1.1102230246251565e-16
>>> np.dot(y, k)
0.0
```

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at

- Prev: Database Options has an unresolved reference to Filegroup [FILESTREAM]
- Next: How would I run a continuous task on an ASP.Net Server?

*1*### In matlab, generating a matrix by adding the elements of two orthogonal vectors

*2*### In matlab, generating a matrix by adding the elements of two orthogonal vectors

*3*### How to generate a vector that orthogonal to other vectors?

*4*### If two plane orthogonal with each other, the transparency of the first plane is wrong

*5*### Orthogonal and Combinatorial testing techniques

*6*### orthogonal projection with numpy

*7*### Daubechies orthogonal wavelet in python

*8*### Numerical evaluation of orthogonal polynomials

*9*### Order orthogonal polygon python

*10*### Converting perspective projection to orthogonal projection

*11*### Orthogonal Projection of Point onto Line

*12*### Orthogonal Projection of Point onto Line

*13*### zgeev giving eigenvectors which are not orthogonal

*14*### When are hash functions orthogonal to each other?

*15*### How to use orthogonal data to sort in DataTables?

*16*### Is there a relationship between CRDTs and the RAFT protocol - or are they orthogonal?

*17*### Draw non-orthogonal axis in matplotlib?

*18*### Orthogonal distance regression in python: meaning of returned values

*19*### Orthogonal projection of a point onto a line in processing?

*20*### Question: Finding overlapping rectangles in an orthogonal Polygon (Java)

*21*### What type of orthogonal polynomials does R use?

*22*### Draw non-orthogonal axis in matplotlib?

*23*### Orthogonal distance regression in python: meaning of returned values

*24*### How to make orthogonal edges with cytoscape.js

*25*### How to detect if all the rows of a non-square matrix are orthogonal in python

*26*### poly() in lm(): difference between raw vs. orthogonal

*27*### Calculating the angle of an orthogonal triangle using the Arcsin in C#

*28*### Draw a square orthogonal to a vector3 (three.js)

*29*### Sorting jquery DataTables on JSON object property - using Orthogonal data

## Comments