【问题标题】:I am unable to understand the execution of following mathematical equation using JavasScript我无法理解使用 Javascript 执行以下数学方程
【发布时间】:2017-02-03 15:21:00
【问题描述】:

我无法理解函数 labelBox 中使用的这行代码this.position = convertlatlonToVec3(cardinal.lat, cardinal.lon).multiplyScalar(radius);。 multiplyScalar(radius) 是如何工作的。

function convertlatlonToVec3(lat, lon)
{
  var cosLat = Math.cos(circle.getCenter().lat() * degrees);
  var sinLat = Math.sin(circle.getCenter().lat() * degrees); 

  var xSphere = radiusEquator * cosLat;
  var ySphere = 0;
  var zSphere = radiusPoles * sinLat;
  var rSphere = Math.sqrt(xSphere*xSphere + ySphere*ySphere + zSphere*zSphere);

  var tmp = rSphere * Math.cos(lat * degrees);    

  xSphere = tmp * Math.cos((lon - circle.getCenter().lng()) * degrees);
  ySphere = tmp * Math.sin((lon - circle.getCenter().lng()) * degrees);
  zSphere = rSphere * Math.sin(lat * degrees);

  var x = -ySphere/circle.getRadius();
  var y = (zSphere*cosLat - xSphere*sinLat)/circle.getRadius();
  var z = 0;

  return new THREE.Vector3(x, y, z);

}

function labelBox(cardinal, radius, root)
{
  this.screenvector = new THREE.Vector3(0,0,0);
  this.labelID = 'MovingLabel'+ cardinal.ID;
  this.position = convertlatlonToVec3(cardinal.lat, cardinal.lon).multiplyScalar(radius);
}

【问题讨论】:

  • convertlatlonToVec3 返回 new THREE.Vector3(x, y, z) ...这可能有一个名为 multiplyScalar 的方法 - 随后会执行
  • @Jaromanda X 我需要知道 multiplyScalar(radius) 是如何工作的。
  • 那么现在您已经改变了问题 - 您查看过three.js 文档吗?
  • @Jaromanda X ya 我查看了 three.js 文档,但找不到有关 multiplyScalar(radius) 的信息。
  • 我通过搜索 three.js Vector3 multiplyScalar 找到了它 - google 中的第一个结果

标签: javascript math three.js


【解决方案1】:

三个.js 文档here
对于THREE.Vector3 multiplyScalar 方法的外观文档是here

.multiplyScalar (s) this
将此向量乘以标量 s。

这个方法的内容可以在in the THREE.Vector3 class找到,看起来像这样:

multiplyScalar: function ( scalar ) {

    if ( isFinite( scalar ) ) {

        this.x *= scalar;
        this.y *= scalar;
        this.z *= scalar;

    } else {

        this.x = 0;
        this.y = 0;
        this.z = 0;

    }

    return this;

},

【讨论】:

    猜你喜欢
    • 2022-11-17
    • 2019-03-05
    • 2017-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-31
    • 2011-09-06
    相关资源
    最近更新 更多