问题描述
我想设置一个平面的旋转。这需要三个数字来表示x,y和z轴的弧度旋转。
I want to set the rotation of a plane. This requires three numbers denoting the rotation in radians in the x, y and z axes.
我没有这些数字,但是,我有一个矢量'myVec'一旦它被旋转,它将与平面正交。
I don't have these numbers, but, I have a vector 'myVec' that shall be orthogonal to the plane once it has been rotated.
这个向量让我向前迈进了一步,但不完全在那里:THREE.Vector3提供了一个函数setEulerFromRotationMatrix 。也许我可以使用它,如果我能弄清楚如何从myVec生成旋转矩阵:
This vector brings me one step closer, but not fully there: THREE.Vector3 provides a function "setEulerFromRotationMatrix". Maybe I could use this, if I could figure out how to generate a rotation matrix from myVec:
旋转矩阵描述了一个向量如何转换为另一个向量。因此出现了一个问题:哪个向量应该是起始向量?这个(1,1,1),或者这个(1,0,0)?。
A rotation matrix describes how one vector transforms into another. Thus emerges the question: which vector should be the start vector? This one (1,1,1), or this one (1,0,0)?.
其次,我如何实际制作矩阵?我看过,但是只找到了如何从旋转矩阵转换为其他东西。
必须以某种方式反转矩阵乘法过程。
Second, how do I actually make the matrix? I have had a look at http://en.wikipedia.org/wiki/Rotation_matrix, but only found how to convert from rotation matrices to something else.It must be something with reversing the matrix multiplication process in some way.
任何指针?
推荐答案
在three.js r50中,默认平面位于原点,而它是正z方向的法线点。因此,您要转换为 myVec
的向量(0,0,1)
。但你不必直接这样做。
In three.js r50, the default plane is located at the origin and it's normal points in the positive-z direction. So it is the vector ( 0, 0, 1 )
that you want to transform to myVec
. But you don't have to do that directly.
在three.js中做你想做的最简单的方法是这样的。
The easiest way to do what you want in three.js is like so.
var v = myPlane.position.clone();
v.add( myVec );
myPlane.lookAt( v );
让three.js为你做数学运算。 : - )
Let three.js do the math for you. :-)
编辑:更新为three.js r.66
Updated to three.js r.66
这篇关于three.js:从平面正交矢量到平面旋转矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!