【问题标题】:equate the length of a vector to a certain value in three.js将向量的长度等同于three.js中的某个值
【发布时间】:2015-05-03 04:07:31
【问题描述】:

我一直在阅读documentationsource 以尝试找出一种方法来计算向量的长度,然后将其设置为定义的值。

我的代码:

if (viewerPosition !== null && placementPosition !== null) {
    var vectorDiff = placementPosition.sub(viewerPosition);
    placementPosition.setY(0);
    placementPosition.multiplyScalar(100000);
    console.log(placementPosition)

日志返回:

Object { x: -23.658385352970377, y: 0, z: 9.121675219786463 }

我尝试添加该行:

placementPosition.length (32);

看看这是否会将向量的长度更改为 32m,但不幸的是这不起作用。

任何建议将不胜感激。谢谢

【问题讨论】:

    标签: javascript three.js


    【解决方案1】:
    // make the length of the vector 1.0
    placementPosition.normalize();
    
    // make the length of the vector 32
    placementPosition.multiplyScalar(32);
    

    【讨论】:

    • 或者使用Vector3.setLength( length );的方法
    • gaitat,这行得通,感谢您也将其放入该格式,这很好地解释了它。 WestLangley,谢谢你给我一个替代版本:)
    猜你喜欢
    • 2022-06-16
    • 1970-01-01
    • 2012-06-03
    • 2022-06-17
    • 2013-08-26
    • 1970-01-01
    • 1970-01-01
    • 2013-05-09
    • 1970-01-01
    相关资源
    最近更新 更多