簡體   English   中英

我無法理解使用JavasScript執行以下數學方程式的方法

[英]I am unable to understand the execution of following mathematical equation using JavasScript

我無法理解這一行代碼this.position = convertlatlonToVec3(cardinal.lat, cardinal.lon).multiplyScalar(radius); 在功能labelBox中使用。 multiplical(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);
}

Three.js文檔在這里
對於THREE.Vector3 multiplyScalar方法看文檔是在這里

.multiplyScalar這個
將此向量乘以標量s。

該方法的內容可以THREE.Vector3類中找到如下所示:

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;

},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM