使用Three.js获取两个3d向量之间的方向? [英] Get direction between two 3d vectors using Three.js?

查看:402
本文介绍了使用Three.js获取两个3d向量之间的方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两点:

v1 = (0, 0, 0);
v2 = (10, 4, -3);

我想获得这两点之间的方向,以便可以从v1到v2进行rayCast.

I want to get the direction between these two points so I can rayCast from point v1 to v2.

我该怎么做?

推荐答案

要创建从v1v2的方向矢量所遵循的模式是:

The pattern to follow to create a direction vector from v1 to v2 is this:

var dir = new THREE.Vector3(); // create once an reuse it

...

dir.subVectors( v2, v1 ).normalize();

Three.js中的方向矢量假定为单位长度.换句话说,必须将它们标准化.如果您在光线投射时使用的方向向量的长度不等于1,那么您将无法获得准确的结果.

Direction vectors in three.js are assumed to have unit-length. In other words, they must be normalized. If the direction vector you use when raycasting does not have length equal to 1, you will not get accurate results.

three.js r.82

three.js r.82

这篇关于使用Three.js获取两个3d向量之间的方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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