Good Evening,
I want to find a way how I can could create a rotation matrix with just 2 normal vectors. One is the origin vector (0,1,0) and one is the normal where I want to move the points to .
So in theory I than have to multiply my r-matrix by every point.
So this picture represents my issue:
I have also googled, I also have found something but I think this isnt what I realy want.
EDIT: This is also ment for 3D space, the picture is just for better understanding.
答案 0 :(得分:0)
Good Morning.
Suppose you want to write the rotation which map
a vector U
to a vector V
. Then W=U^V
(cross product) is the axe of rotation and is an invariant. Let M
be the associated matrix.
We have finally:
(V,W,V^W) = M.(U,W,U^W)
Now let write the code :
from pylab import cross,dot,inv
def rot(U,V):
W=cross(U,V)
A=np.array([U,W,cross(U,W)]).T
B=np.array([V,W,cross(V,W)]).T
return dot(B,inv(A))
An example :
In [2]: U = np.array([4, 3, 8])
Out[3]: V = np.array([1, 3, 4])
In [6]: M=rot(U,V)
In [7]: dot(M,U)
Out[7]: array([ 1., 3., 4.])
In [9]: W=cross(U,V)
In [10]: allclose(W,dot(M,W))
Out[10]: True
Note that U
and V
need not to be unit vectors, just not parallel. The transformation is a rotation if the norms are equal.