如何在THREE.js中找到两个向量之间的旋转矩阵 [英] How to find rotation matrix between two vectors in THREE.js

查看:800
本文介绍了如何在THREE.js中找到两个向量之间的旋转矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在THREE.js中两个定义的向量之间找到旋转矩阵的方法.

I'm looking for the way to find rotation matrix between two defined vectors in THREE.js.

例如

v1 = new THREE.Vector3(1, 1, 1) v2 = new THREE.Vector3(1, 1, -1)

下一步,我需要这个旋转矩阵来旋转整个对象.

I need this rotation matrix to rotate whole object in next step.

推荐答案

您可以从两个单位长度矢量v1v2定义旋转,如下所示:

You can define a rotation from two unit-length vectors v1 and v2 like so:

var quaternion = new THREE.Quaternion(); // create one and reuse it

quaternion.setFromUnitVectors( v1, v2 );

在这种情况下,您需要先对向量进行归一化.

In your case, you need to normalize your vectors first.

然后您可以使用以下模式将该旋转应用于对象:

You can then apply that rotation to an object using the following pattern:

var matrix = new THREE.Matrix4(); // create one and reuse it

matrix.makeRotationFromQuaternion( quaternion );

object.applyMatrix( matrix );

或者,如果不需要矩阵,则可以直接应用四元数:

Alternatively, if you do not require the matrix, you can just apply the quaternion directly:

object.applyQuaternion( quaternion );

three.js r.86

three.js r.86

这篇关于如何在THREE.js中找到两个向量之间的旋转矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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