简体   繁体   English

three.js:从平面正交矢量到平面旋转矩阵

[英]three.js: from plane-orthogonal vector to plane rotation matrix

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. 这需要三个数字来表示x,y和z轴的弧度旋转。

I don't have these numbers, but, I have a vector 'myVec' that shall be orthogonal to the plane once it has been rotated. 我没有这些数字,但是,我有一个矢量'myVec',它一旦旋转就应该与平面正交。

This vector brings me one step closer, but not fully there: THREE.Vector3 provides a function "setEulerFromRotationMatrix". 这个向量让我向前迈进了一步,但并不完全在那里:THREE.Vector3提供了一个函数“setEulerFromRotationMatrix”。 Maybe I could use this, if I could figure out how to generate a rotation matrix from myVec: 也许我可以使用它,如果我能弄清楚如何从myVec生成旋转矩阵:

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)?. 这一个(1,1,1),还是这一个(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. 我看过http://en.wikipedia.org/wiki/Rotation_matrix ,但只发现了如何从旋转矩阵转换为其他东西。 It must be something with reversing the matrix multiplication process in some way. 它必须以某种方式逆转矩阵乘法过程。

Any pointers? 有什么指针吗?

In three.js r50, the default plane is located at the origin and it's normal points in the positive-z direction. 在three.js r50中,默认平面位于原点,而它是正z方向的法线点。 So it is the vector ( 0, 0, 1 ) that you want to transform to myVec . 所以你想要转换为myVec是向量( 0, 0, 1 ) myVec But you don't have to do that directly. 但你不必直接这样做。

The easiest way to do what you want in three.js is like so. 在three.js中做你想做的最简单的方法就是这样。

var v = myPlane.position.clone();
v.add( myVec );
myPlane.lookAt( v );

Let three.js do the math for you. 让three.js为你做数学运算。 :-) :-)

EDIT: Updated to three.js r.66 编辑:更新为three.js r.66

Any rotation in three dimensions can be represented by three angles. 三维中的任何旋转都可以用三个角度表示。 Your method sounds like Euler angles, have a look here: http://en.wikipedia.org/wiki/Euler_angles 你的方法听起来像欧拉角,看看这里: http//en.wikipedia.org/wiki/Euler_angles

When you want to construct a rotation matrix for a rotation around 3 angles at once, you have to construct 3 matrices first, each of which performs rotation around one axis by a given angle. 如果要为一次旋转3个角度构建旋转矩阵,则必须首先构造3个矩阵,每个矩阵围绕一个轴旋转给定角度。 Then you have to multiply the 3 matrices (in the correct order) to get your final rotation matrix. 然后你必须乘以3个矩阵(按照正确的顺序)来得到你的最终旋转矩阵。

If you know how to rotate the vector (1 0 0) to match your final vector, you just need to figure out the angles around the respective axes. 如果您知道如何旋转矢量(1 0 0)以匹配最终矢量,则只需要计算出各个轴周围的角度。 Mind the order of the rotations. 注意旋转的顺序。 You may start with any other vector, too. 您也可以从任何其他矢量开始。 You just need to know the angles. 你只需要知道角度。

A matrix which rotates around a given axis by a given angle can be found here: http://en.wikipedia.org/wiki/Rotation_matrix (see "Basic rotations" under "In three dimensions"). 可以在此处找到围绕给定轴旋转给定角度的矩阵: http//en.wikipedia.org/wiki/Rotation_matrix (参见“三维”下的“基本旋转”)。

Under "General rotations" you'll find the method I just described to you (multiplying 3 matrices to get one matrix for the entire rotation). 在“一般旋转”下,您将找到我刚才描述的方法(将3个矩阵相乘以获得整个旋转的一个矩阵)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM