三.js:从平面正交向量到平面旋转矩阵 [英] three.js: from plane-orthogonal vector to plane rotation matrix

查看:19
本文介绍了三.js:从平面正交向量到平面旋转矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置平面的旋转.这需要三个数字来表示 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)?.

第二,我实际上如何制作矩阵?我看过http://en.wikipedia.org/wiki/Rotation_matrix,但是只找到了如何从旋转矩阵转换为其他东西.它必须以某种方式反转矩阵乘法过程.

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

这篇关于三.js:从平面正交向量到平面旋转矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆